/* ============================================
   UVLIS — Chess Module Styles
   Premium dark-mode chess UI
   ============================================ */

/* ── Keyframes ───────────────────────────────────────────────────────────── */

@keyframes piecePop {
  0%   { transform: scale(0.7); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes kingPulse {
  0%, 100% { background-color: rgba(239, 68, 68, 0.55); }
  50%       { background-color: rgba(239, 68, 68, 0.9); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes modalPopIn {
  from { opacity: 0; transform: scale(0.9) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

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

@keyframes glowPulse {
  0%, 100% { box-shadow: var(--shadow-glow); }
  50%       { box-shadow: 0 0 50px rgba(124, 58, 237, 0.55); }
}

@keyframes moveSquarePulse {
  0%   { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); }
  50%  { box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.28); }
  100% { box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); }
}

@keyframes bannerPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1px); }
}

/* ── [hidden] override ───────────────────────────────────────────────────────
   CSS id/class rules have higher specificity than the browser's default
   [hidden]{display:none}, so explicit display values would always show the
   element even when the hidden attribute is set. These rules restore the
   expected behaviour. */

#chess-game-view[hidden],
#chess-waiting-view[hidden],
.chess-modal-overlay[hidden],
.chess-promo-overlay[hidden] {
  display: none !important;
}

/* ── Layout shell ────────────────────────────────────────────────────────── */

#chess-app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
}

/* ── Lobby ───────────────────────────────────────────────────────────────── */

#chess-lobby {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 28px 48px;
  animation: fadeUp 0.35s ease both;
}

/* Hero card — consistent with the other game lobbies (dibujitos / umo) */
.chess-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.16), rgba(34, 211, 238, 0.06));
  border: 1px solid var(--border-default);
  border-radius: 20px;
  padding: 26px 28px;
  margin-bottom: 26px;
}

.chess-hero-titles {
  min-width: 0;
}

.chess-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(124, 58, 237, 0.16);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--primary-200);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.chess-hero h1 {
  font-family: 'Poppins', sans-serif;
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 8px;
  line-height: 1.15;
}

.chess-hero p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 620px;
  line-height: 1.5;
  margin: 0;
}

/* Rooms section header — matches .dib-rooms-head / .dib-section-title */
.chess-rooms-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.chess-section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.chess-count {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.chess-topbar-actions {
  margin-left: auto;
}

.chess-create-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  background: var(--gradient-primary);
  border: none;
  border-radius: 12px;
  color: #fff;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, filter 0.15s ease;
}

.chess-create-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.chess-create-btn:active {
  transform: translateY(0);
}

.chess-create-sm {
  padding: 8px 14px;
  font-size: 0.84rem;
}

.chess-games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.chess-game-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.chess-game-card:hover {
  border-color: rgba(124, 58, 237, 0.35);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.chess-game-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chess-card-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.chess-card-info {
  flex: 1;
  min-width: 0;
}

.chess-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chess-card-meta {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.chess-card-bet {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--warning-400);
}

.chess-card-bet .bet-icon {
  font-size: 1rem;
}

.chess-join-btn {
  width: 100%;
  padding: 10px 0;
  background: transparent;
  border: 1px solid var(--primary-500);
  border-radius: var(--radius-md);
  color: var(--primary-300);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.15s;
}

.chess-join-btn:hover:not(:disabled) {
  background: var(--primary-500);
  color: #fff;
  transform: translateY(-1px);
}

.chess-join-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Own open game: re-enter + cancel actions */
.chess-card-own-actions {
  display: flex;
  gap: 8px;
}
.chess-reenter-btn {
  flex: 1;
  padding: 10px 0;
  background: var(--primary-500);
  border: 1px solid var(--primary-500);
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, transform 0.15s;
}
.chess-reenter-btn:hover { background: var(--primary-600); transform: translateY(-1px); }
.chess-cancel-open-btn {
  flex-shrink: 0;
  padding: 10px 16px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-md);
  color: var(--danger-400);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s;
}
.chess-cancel-open-btn:hover:not(:disabled) { background: rgba(239, 68, 68, 0.2); }
.chess-cancel-open-btn:disabled { opacity: 0.5; cursor: default; }

.chess-empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.chess-empty-state .empty-icon {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 12px;
  opacity: 0.5;
}

.chess-empty-state p {
  margin: 0;
  font-size: 0.95rem;
}

/* ── Waiting view ────────────────────────────────────────────────────────── */

#chess-waiting-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  padding: 32px;
}

.chess-waiting-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  text-align: center;
  max-width: 400px;
  width: 100%;
  animation: fadeUp 0.3s ease both;
}

.chess-waiting-card h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text-primary);
}

.chess-waiting-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-overlay);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 24px auto;
}

.chess-waiting-game-id {
  background: var(--bg-overlay);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--accent-500);
  margin: 12px 0;
  letter-spacing: 0.1em;
}

.chess-waiting-bet {
  color: var(--warning-400);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.chess-waiting-bet-zero {
  color: var(--text-muted);
}

.chess-cancel-btn {
  padding: 11px 28px;
  background: transparent;
  border: 1px solid var(--danger-500);
  border-radius: var(--radius-md);
  color: var(--danger-400);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.chess-cancel-btn:hover {
  background: var(--danger-500);
  color: #fff;
}

/* ── Game view ───────────────────────────────────────────────────────────── */

#chess-game-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
  gap: 10px;
  animation: fadeUp 0.3s ease both;
  width: 100%;
  box-sizing: border-box;
}

/* ── Player panels ───────────────────────────────────────────────────────── */

.chess-player-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  transition: border-color 0.25s;
}

.chess-player-panel.active-turn {
  border-color: rgba(124, 58, 237, 0.5);
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.15);
}

.chess-player-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.chess-player-info {
  flex: 1;
  min-width: 0;
}

.chess-player-name {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chess-player-color-label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.chess-turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success-500);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.2s;
}

.chess-player-panel.active-turn .chess-turn-dot {
  opacity: 1;
  animation: dotPulse 1.2s ease-in-out infinite;
}

/* ── Turn banner ─────────────────────────────────────────────────────────── */

.chess-turn-banner {
  width: 100%;
  max-width: 560px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.92), rgba(17, 24, 39, 0.76));
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  margin-top: 2px;
}

.chess-turn-banner-label {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.chess-turn-banner-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.chess-turn-banner.my-turn {
  border-color: rgba(124, 58, 237, 0.58);
  background: linear-gradient(180deg, rgba(91, 63, 168, 0.22), rgba(17, 24, 39, 0.86));
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.18);
  animation: bannerPulse 1.2s ease-in-out infinite;
}

.chess-turn-banner.my-turn .chess-turn-banner-label {
  color: #efe6ff;
}

.chess-turn-banner.opponent-turn {
  border-color: rgba(59, 130, 246, 0.38);
  background: linear-gradient(180deg, rgba(30, 64, 175, 0.18), rgba(17, 24, 39, 0.82));
}

.chess-turn-banner.in-check {
  border-color: rgba(239, 68, 68, 0.55);
  background: linear-gradient(180deg, rgba(127, 29, 29, 0.22), rgba(17, 24, 39, 0.88));
}

/* ── Board container ─────────────────────────────────────────────────────── */

.chess-board-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 4px 0;
  transition: filter 0.18s ease, transform 0.18s ease;
}

.chess-board-container.my-turn .chess-board {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(124, 58, 237, 0.3), 0 0 26px rgba(124, 58, 237, 0.28);
}

.chess-board-container.opponent-turn .chess-board {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(59, 130, 246, 0.18);
}

.chess-board-container.in-check .chess-board {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(239, 68, 68, 0.35), 0 0 24px rgba(239, 68, 68, 0.22);
}

.chess-board-with-coords {
  display: grid;
  grid-template-columns: 22px 1fr;
  grid-template-rows: 1fr 22px;
  gap: 0;
  align-items: start;
}

.chess-coords-ranks {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  height: min(560px, calc(100vw - 48px));
  padding: 0 4px 0 0;
  grid-row: 1;
  grid-column: 1;
}

.chess-coords-ranks span,
.chess-coords-files span {
  font-size: clamp(9px, 1.5vw, 12px);
  color: var(--text-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(min(560px, calc(100vw - 48px)) / 8);
  user-select: none;
}

.chess-coords-files {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  width: min(560px, calc(100vw - 48px));
  padding: 4px 0 0;
  grid-row: 2;
  grid-column: 2;
}

.chess-coords-files span {
  width: calc(min(560px, calc(100vw - 48px)) / 8);
  height: auto;
}

/* ── Chess board ─────────────────────────────────────────────────────────── */

.chess-board {
  width: min(560px, calc(100vw - 48px));
  height: min(560px, calc(100vw - 48px));
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid rgba(124, 58, 237, 0.4);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), var(--shadow-glow);
  grid-row: 1;
  grid-column: 2;
}

.chess-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.12s;
  user-select: none;
}

.chess-square.light {
  background-color: #d4c5f2;
}

.chess-square.dark {
  background-color: #5b3fa8;
}

.chess-square.selected {
  background-color: rgba(251, 191, 36, 0.75) !important;
}

.chess-square.last-move {
  background-color: rgba(124, 58, 237, 0.5) !important;
}

.chess-square.last-move.light {
  background-color: rgba(124, 58, 237, 0.38) !important;
}

.chess-square.last-move.dark {
  background-color: rgba(124, 58, 237, 0.6) !important;
}

/* Legal move dot (empty square) */
.chess-square.legal::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.22);
  pointer-events: none;
  z-index: 2;
}

.chess-square.legal.light::after {
  background: rgba(0, 0, 0, 0.18);
}

.chess-square.legal.dark::after {
  background: rgba(0, 0, 0, 0.28);
}

/* Legal capture ring */
.chess-square.legal-capture::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0;
  background: transparent;
  border: 3.5px solid rgba(0, 0, 0, 0.22);
  pointer-events: none;
  z-index: 2;
  border-radius: 50%;
  width: 86%;
  height: 86%;
  top: 7%;
  left: 7%;
}

.chess-square.check-king {
  animation: kingPulse 0.8s ease-in-out infinite;
}

.chess-square.move-origin-flash,
.chess-square.move-target-flash {
  animation: moveSquarePulse 0.42s ease-out;
}

/* ── Pieces ──────────────────────────────────────────────────────────────── */

.chess-piece {
  cursor: grab;
  transition: transform 0.12s ease;
  position: relative;
  z-index: 3;
  user-select: none;
  width: 85%;
  height: 85%;
  object-fit: contain;
  pointer-events: auto; /* Required for drag events to fire on the img */
}

.chess-piece:active {
  cursor: grabbing;
}

.chess-piece:hover {
  transform: scale(1.1);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.piece-pop {
  animation: piecePop 0.22s ease both;
}

.piece-hidden-during-animation {
  opacity: 0;
}

.chess-piece-ghost {
  position: fixed;
  z-index: 9998;
  pointer-events: none;
  transition: transform 0.32s cubic-bezier(0.2, 0.75, 0.15, 1);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}

/* ── Controls ────────────────────────────────────────────────────────────── */

#chess-controls {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 560px;
}

.chess-ctrl-btn {
  flex: 1;
  min-width: 120px;
  max-width: 200px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.chess-ctrl-btn:hover:not(:disabled) {
  border-color: var(--primary-500);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.chess-ctrl-btn.danger:hover:not(:disabled) {
  border-color: var(--danger-500);
  color: var(--danger-400);
}

.chess-ctrl-btn.accept:hover:not(:disabled) {
  border-color: var(--success-500);
  color: var(--success-500);
}

.chess-ctrl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Status bar ──────────────────────────────────────────────────────────── */

#chess-status {
  width: 100%;
  max-width: 560px;
  margin-top: 10px;
  text-align: center;
}

.chess-status-bar {
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  font-weight: 500;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.chess-status-bar.my-turn {
  border-color: rgba(124, 58, 237, 0.4);
  color: var(--primary-300);
  background: rgba(124, 58, 237, 0.08);
}

.chess-status-bar.in-check {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--danger-400);
  background: rgba(239, 68, 68, 0.08);
}

.chess-status-bar.draw-offer {
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--warning-400);
  background: rgba(245, 158, 11, 0.08);
}

/* ── Result overlay ──────────────────────────────────────────────────────── */

.chess-result-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 15, 0.94);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 40px 48px;
  text-align: center;
  z-index: 20;
  min-width: 280px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), var(--shadow-glow);
  animation: slideIn 0.3s ease both;
  backdrop-filter: blur(20px);
}

.chess-result-icon {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 12px;
}

.chess-result-title {
  font-family: 'Poppins', sans-serif;
  font-size: 1.7rem;
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0 0 8px;
}

.chess-result-message {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 24px;
  line-height: 1.5;
}

.chess-result-lobby-btn {
  padding: 12px 32px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: var(--font-size-base);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s;
  box-shadow: var(--shadow-glow);
}

.chess-result-lobby-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(124, 58, 237, 0.5);
}

.chess-board-container {
  position: relative;
}

/* ── Promotion modal ─────────────────────────────────────────────────────── */

.chess-promo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  backdrop-filter: blur(6px);
}

.chess-promo-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 32px;
  text-align: center;
  animation: modalPopIn 0.25s ease both;
}

.chess-promo-modal h3 {
  margin: 0 0 20px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.chess-promo-pieces {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.chess-promo-piece {
  width: 70px;
  height: 70px;
  border: 2px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-family: 'Apple Symbols', 'Segoe UI Symbol', 'Noto Sans Symbols 2', 'Arial Unicode MS', sans-serif;
  font-weight: 400;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.chess-promo-piece:hover {
  border-color: var(--primary-500);
  background: var(--bg-hover);
  transform: scale(1.07);
}

/* ── Create modal ────────────────────────────────────────────────────────── */

.chess-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  backdrop-filter: blur(6px);
}

.chess-create-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 36px 40px;
  width: min(420px, 90vw);
  animation: modalPopIn 0.25s ease both;
}

.chess-create-modal h2 {
  font-family: 'Poppins', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 8px;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chess-create-modal p {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  margin: 0 0 24px;
}

.chess-modal-field {
  margin-bottom: 20px;
}

.chess-modal-field label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.chess-modal-field input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--font-size-base);
  box-sizing: border-box;
  transition: border-color 0.18s;
  -moz-appearance: textfield;
}

.chess-modal-field input[type="number"]::-webkit-outer-spin-button,
.chess-modal-field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.chess-modal-field input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-500);
}

.chess-modal-balance {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 6px;
}

.chess-modal-balance span {
  color: var(--warning-400);
  font-weight: 600;
}

.chess-modal-actions {
  display: flex;
  gap: 10px;
}

.chess-modal-actions button {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  border: none;
}

.chess-modal-cancel {
  background: var(--bg-overlay);
  border: 1px solid var(--border-default) !important;
  color: var(--text-secondary);
}

.chess-modal-cancel:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chess-modal-submit {
  background: var(--gradient-primary);
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.chess-modal-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 30px rgba(124, 58, 237, 0.5);
}

/* ── Toast ───────────────────────────────────────────────────────────────── */

.chess-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.chess-toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: #fff;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.25s ease both;
  max-width: 320px;
  pointer-events: auto;
}

.chess-toast.error {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--danger-400);
}

.chess-toast.success {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  color: var(--success-500);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  #chess-lobby {
    padding: 20px 16px 40px;
  }

  .chess-hero {
    padding: 20px;
  }

  .chess-hero h1 {
    font-size: 1.5rem;
  }

  .chess-hero-create {
    width: 100%;
    justify-content: center;
  }

  .chess-turn-banner {
    padding: 10px 12px;
  }

  .chess-turn-banner-label {
    font-size: 0.95rem;
  }

  .chess-board {
    width: min(560px, 90vw);
    height: min(560px, 90vw);
  }

  .chess-coords-ranks {
    height: min(560px, 90vw);
  }

  .chess-coords-files {
    width: min(560px, 90vw);
  }

  .chess-player-panel {
    max-width: 90vw;
  }

  #chess-controls {
    max-width: 90vw;
  }

  #chess-status {
    max-width: 90vw;
  }

  .chess-promo-piece {
    width: 56px;
    height: 56px;
    font-size: 2rem;
  }

  .chess-create-modal {
    padding: 28px 24px;
  }
}

/* ── Lobby tabs (Partidas / Ranking) ─────────────────────────────────────── */
.chess-lobby-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.chess-lobby-tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}

.chess-lobby-tab:hover { color: var(--text-primary); }

.chess-lobby-tab.active {
  color: var(--primary-300);
  border-bottom-color: var(--primary-500);
}

.chess-ranking-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 4px 0 0;
}

/* ── Ranking list ────────────────────────────────────────────────────────── */
.chess-my-rank {
  margin-bottom: 18px;
}

.chess-my-rank-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.chess-my-rank-empty {
  padding: 16px;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.chess-ranking-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chess-rank-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--surface-1, rgba(255,255,255,0.02));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.chess-rank-row.me {
  border-color: var(--primary-500);
  background: rgba(99, 102, 241, 0.08);
}

.chess-rank-pos {
  min-width: 34px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-muted);
}

.chess-rank-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-primary);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}

.chess-rank-main { flex: 1; min-width: 0; }

.chess-rank-name {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chess-rank-record {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.chess-rank-elo {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}

.chess-rank-elo-num {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--primary-200);
}

.chess-rank-elo-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-muted);
}

/* ── ELO change on result overlay ────────────────────────────────────────── */
.chess-result-elo {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 4px 0 14px;
}

.chess-result-elo-new {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
}

.chess-result-elo-delta {
  font-size: 1rem;
  font-weight: 800;
}

.chess-result-elo-delta.up { color: var(--success-400, #34d399); }
.chess-result-elo-delta.down { color: var(--danger-400, #f87171); }
.chess-result-elo-delta.even { color: var(--text-muted); }

/* ── Chess clock ─────────────────────────────────────────────────────────── */
.chess-clock {
  flex-shrink: 0;
  min-width: 74px;
  text-align: center;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-base, rgba(0,0,0,0.25));
  border: 1px solid var(--border-default);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: .02em;
  color: var(--text-secondary, #cbd5e1);
  transition: background .2s, color .2s, border-color .2s;
}

.chess-clock.ticking {
  background: var(--gradient-primary);
  border-color: transparent;
  color: #fff;
}

.chess-clock.low {
  color: var(--danger-400, #f87171);
}

.chess-clock.ticking.low {
  background: var(--danger-500, #ef4444);
  color: #fff;
  animation: clockPulse 1s ease-in-out infinite;
}

.chess-clock.flagged {
  opacity: 0.55;
  text-decoration: line-through;
}

@keyframes clockPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* ── Time-control selector (create modal) ────────────────────────────────── */
.chess-time-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.chess-time-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary, #cbd5e1);
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}

.chess-time-opt:hover { border-color: var(--primary-500); }
.chess-time-opt:active { transform: scale(0.97); }

.chess-time-opt.active {
  border-color: var(--primary-500);
  background: rgba(99, 102, 241, 0.12);
}

.chess-time-opt .tc-main {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.chess-time-opt .tc-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Lobby card badges (time control + bet) ──────────────────────────────── */
.chess-card-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 4px 0;
}

.chess-card-tc {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-200);
  background: rgba(99, 102, 241, 0.12);
  border-radius: var(--radius-full, 999px);
  padding: 3px 10px;
}

@media (max-width: 560px) {
  .chess-time-grid { grid-template-columns: repeat(3, 1fr); }
  .chess-clock { min-width: 64px; font-size: 1.05rem; padding: 5px 8px; }
}
