/* =========================================================================
   CHESS WEB3 - LICHESS INSPIRED GAMEFI DESIGN
   ========================================================================= */

/* ===== VARIABLES ===== */
:root {
  /* Theme Colors - Updated to match Auth page */
  --pk-primary: #8b5cf6;
  --pk-secondary: #3b82f6;
  --pk-accent: #a78bfa;

  /* Backgrounds */
  --bg-body: #0d1117;
  --bg-panel: #161b22;
  --bg-input: #21262d;
  --bg-highlight: rgba(139, 92, 246, 0.2);

  /* Text */
  --text-main: #c9d1d9;
  --text-bright: #f0f6fc;
  --text-dim: #8b949e;

  /* Borders */
  --border-color: #30363d;

  /* Status */
  --status-good: #10b981;
  --status-bad: #f85149;
  --status-draw: #3b82f6;

  /* Dimensions */
  --board-size: min(80vh, 600px);
  --sidebar-width: 320px;
  --header-height: 60px;
}

/* ===== RESET & BASE ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  /* App-like feel */
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
.top-bar {
  height: var(--header-height);
  background: var(--bg-panel);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  position: relative;
}

.header-left {
  position: absolute;
  left: 20px;
  display: flex;
  align-items: center;
}

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

.rewards-icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  margin-top: -2px;
  transition: transform 0.2s, opacity 0.2s;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 5px;
}

.rewards-icon-btn:hover {
  transform: scale(1.1);
  opacity: 1;
}

.rewards-icon-btn::after {
  content: 'Reglas y Recompensas';
  font-size: 0.7rem;
  color: var(--pk-accent);
  opacity: 0;
  visibility: hidden;
  transition: 0.2s;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.rewards-icon-btn:hover::after {
  opacity: 1;
  visibility: visible;
}

.header-right {
  position: absolute;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-img {
  height: 45px;
  width: auto;
  display: block;
  object-fit: contain;
  transform: scale(4.2);
  transform-origin: left center;
  margin-left: 15px;
  margin-top: 8px;
  pointer-events: none;
  /* Prevents overlap from blocking clicks */
}

.header-center-grid {
  display: grid;
  grid-template-columns: var(--board-size) var(--sidebar-width);
  grid-gap: 24px;
  align-items: center;
}

.dashboard {
  display: flex;
  gap: 15px;
  grid-column: 1;
  justify-content: flex-start;
}

.stat-box {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Slightly tighter gap */
  font-size: 0.95rem;
  /* Slightly smaller font */
  padding: 6px 12px;
  /* Smaller padding */
  border-radius: 4px;
  background: #302e2c;
  border-bottom: 2px solid transparent;
  transition: 0.2s;
  min-width: 110px;
  /* Reduced from 140px */
  justify-content: center;
  /* Center content to keep it compact */
  position: relative;
}

/* Base Hover */
.stat-box:hover {
  background: #403d39;
}

/* CP: Blue Border, No Glow */
.stat-box.cp {
  border-bottom: 2px solid #00f2ff;
}

.stat-box.cp .stat-value {
  color: #d0fdff;
}

/* CHESS: Gold Border, No Glow */
.stat-box.chess {
  border-bottom: 2px solid #ffd700;
}

.stat-box.chess .stat-value {
  color: #fff8d6;
}

/* ELO: Draw Border (Blueish) or Standard */
.stat-box.elo {
  border-bottom: 2px solid var(--text-dim);
}

/* Stat Value Styling for PGN placeholder */
.stat-box.pgn-top {
  border-bottom: 2px solid var(--pk-primary);
  cursor: pointer;
}

.stat-box.pgn-top:hover {
  background: var(--pk-primary);
}

.stat-box.pgn-top:hover .stat-icon,
.stat-box.pgn-top:hover .stat-label {
  color: white;
}

/* Label Handling (Tooltip Style) */
.stat-label {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(5px);
  background: #1c1c1c;
  color: #ffffff;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 100;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* Tooltip Arrow */
.stat-label::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--border-color);
}

/* Show Labels on Hover WITHOUT resizing */
.stat-box:hover .stat-label {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.history-link {
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: 4px;
  background: #302e2c;
  transition: 0.2s;
}

.history-link:hover {
  background: #403d39;
  color: var(--text-bright);
}

/* ===== HISTORY DROPDOWN (Hover) ===== */
.history-dropdown {
  position: relative;
  display: inline-block;
}

.history-dropdown .dropdown-content {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 160px;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.2s ease;
  padding: 8px 0;
  margin-top: 5px;
}

.history-dropdown:hover .dropdown-content {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.history-dropdown .dropdown-item {
  padding: 10px 16px;
  color: var(--text-main);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.2s;
  cursor: pointer;
  font-size: 0.9rem;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.history-dropdown .dropdown-item:hover {
  background: var(--bg-highlight);
  color: var(--text-bright);
}

.history-dropdown .dropdown-divider {
  height: 1px;
  background: var(--border-color);
  margin: 5px 0;
}

/* ===== WITHDRAWAL HISTORY TABLE ===== */
.withdrawal-history-table-container {
  width: 100%;
  overflow-x: auto;
  margin-top: 15px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.withdrawal-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.2);
}

.withdrawal-history-table th {
  text-align: left;
  padding: 12px 15px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
}

.withdrawal-history-table td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.withdrawal-history-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.status-badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-pending {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid #f59e0b;
}

.status-processing {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
  border: 1px solid #3b82f6;
}

.status-completed {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid #10b981;
}

.status-failed {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid #ef4444;
}

.status-rejected {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
  border: 1px solid #9ca3af;
}

.tx-hash-link {
  color: var(--pk-primary);
  text-decoration: none;
  font-family: monospace;
  display: flex;
  align-items: center;
  gap: 5px;
}

.tx-hash-link:hover {
  text-decoration: underline;
}

.modal-content.wide {
  max-width: 900px !important;
  width: 95% !important;
}

/* ===== USER AVATAR MENU ===== */
.user-menu {
  position: relative;
  margin-left: 8px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #059669);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.4);
}

.user-avatar span {
  color: white;
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  z-index: 1000;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.15s, transform 0.15s;
}

.user-dropdown.hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.dropdown-header {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-username {
  color: var(--text-bright);
  font-weight: 600;
  font-size: 0.95rem;
}

.dropdown-email {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color);
}

.dropdown-item {
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.dropdown-item#logout-btn:hover {
  background: rgba(248, 81, 73, 0.1);
  color: var(--status-bad);
}

.disconnect-icon-btn {
  opacity: 0.6;
  filter: grayscale(1);
}

.disconnect-icon-btn:hover {
  opacity: 1;
  filter: grayscale(0);
  transform: scale(1.2);
}

.wallet-address {
  cursor: help;
}

/* ===== MAIN LAYOUT ===== */
.main-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  /* Center vertically */
  padding: 20px;
  overflow-y: auto;
}

.game-area {
  display: grid;
  grid-template-columns: var(--board-size) var(--sidebar-width);
  grid-gap: 24px;
  align-items: start;
}

/* ===== BOARD SECTION ===== */
.board-container {
  display: flex;
  flex-direction: column;
}

#board {
  width: 100% !important;
  /* Force width to container */
  aspect-ratio: 1/1;
  border-radius: 4px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

#status {
  text-align: center;
  padding: 10px;
  margin-top: 10px;
  font-weight: 500;
  color: var(--text-bright);
}

/* ===== SIDEBAR WRAPPER (Lichess Style) ===== */
.sidebar-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: var(--board-size);
  width: 350px;
}

.sidebar-main {
  flex: 1;
  background: var(--bg-panel);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  margin: 10px 0;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.player-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  font-size: 1.2rem;
  opacity: 0.8;
}

.name {
  color: var(--text-bright);
  font-weight: 600;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rating-inline {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 0.9rem;
}

/* Timers (Tab Style) */
.timer-tab {
  background: #262421;
  padding: 8px 15px;
  border-radius: 4px;
  font-family: 'Orbitron', monospace;
  /* Modern clock font if available, fallback monospace */
  font-size: 1.8rem;
  font-weight: 700;
  color: #bababa;
  border-left: 5px solid transparent;
  transition: all 0.3s ease;
  min-width: 100px;
  text-align: right;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.timer-tab.active {
  background: #363430;
  color: #ffffff;
  border-left-color: var(--status-good);
}

.timer-tab.warning {
  color: #facc15;
}

.timer-tab.danger {
  color: #ff4d4d;
}

.timer.danger {
  color: var(--status-bad);
}

/* Moves History */
.moves-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #262421;
  /* Darker than panel */
  overflow: hidden;
}

.moves-header {
  padding: 8px 16px;
  background: #302e2c;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: bold;
  border-bottom: 1px solid #262421;
  display: flex;
  justify-content: space-between;
}

.move-history-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  scroll-behavior: smooth;
}

#moves {
  list-style: none;
  font-family: monospace;
  font-size: 1rem;
  display: table;
  /* Use table layout for neat columns */
  width: 100%;
  border-collapse: collapse;
}

#moves li {
  display: table-row;
}

#moves li span {
  display: table-cell;
  padding: 4px 12px;
}

/* We create pseudo-elements in JS OR we style the li if it contains text directly. 
   Usually history is formatted as "1. e4 e5".
   If existing JS just appending text to LI:
   <li class="move-row"><span class="move-num">1.</span><span class="white-move">e4</span><span class="black-move">e5</span></li>
   I might need to adjust JS for this table layout or just use grid */

#moves {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  padding: 10px;
}

#moves li {
  width: 50%;
  /* 2 items per row if listing single moves? No, usually JS adds pairs. 
                 Existing JS likely adds "White Black" or just lists moves. 
                 Code check: `movesEl.innerHTML = ''`... JS not visible in `style.css` 
                 but standard chess.js implementation usually lists full history. 
                 I'll stick to a simple list for now and refine in JS if needed. */
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  border-bottom: 1px solid #303030;
}

#moves li:nth-child(even) {
  background: #2b2926;
}

#moves li:hover {
  background: #366ac3;
  color: white;
  cursor: pointer;
}

/* Controls */
.game-controls {
  padding: 16px;
  background: #302e2c;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.icon-btn {
  flex: 1;
  background: #403d39;
  border: none;
  color: var(--text-main);
  padding: 10px;
  border-radius: 4px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: 0.2s;
}

.icon-btn:hover {
  background: #504d49;
  color: var(--text-bright);
}

.icon-btn[title="Rendirse (Resign)"]:hover {
  background: #cc3333;
  color: white;
}

.main-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--pk-primary), var(--pk-secondary));
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-icon {
  font-size: 1.3rem;
  /* Slightly larger than text but proportionate */
  line-height: 1;
  display: flex;
  align-items: center;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.primary-btn.searching {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

.secondary-btn {
  width: 100%;
  padding: 10px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid var(--pk-primary);
  color: var(--pk-accent);
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--pk-accent);
  color: var(--text-bright);
}

/* === Inline Cancel X inside Play Button === */
#play-online {
  position: relative;
}

#play-online .btn-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cancel-x {
  margin-left: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}

.cancel-x:hover {
  color: #fff;
  background: rgba(248, 81, 73, 0.5);
}

.cancel-x.hidden {
  display: none;
}

/* Primer Movimiento Banner */
/* Primer Movimiento Banner */
.first-move-banner {
  background: #629924;
  /* Verde estilo Lichess */
  color: white;
  text-align: center;
  padding: 4px 0;
  font-size: 0.8rem;
  font-weight: 600;
  width: 100%;
  animation: slideDown 0.3s ease-out;
}

.first-move-banner.warning {
  background: #d32f2f;
  /* Rojo sólido estándar */
  animation: none;
}

@keyframes slideDown {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse-red {
  from {
    box-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
  }

  to {
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
  }
}

/* Time Selector */
.time-selector {
  display: flex;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 4px;
}

.time-option {
  flex: 1;
  cursor: pointer;
  position: relative;
}

.time-option input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.time-label {
  display: block;
  padding: 8px;
  text-align: center;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  transition: all 0.2s;
  background: transparent;
}

.time-option input:checked+.time-label {
  background: var(--pk-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.time-option:hover .time-label:not(input:checked + .time-label) {
  background: rgba(139, 92, 246, 0.1);
  color: var(--text-bright);
}

/* Overlays */
.draw-overlay {
  background: #262421;
  padding: 10px;
  border: 1px solid var(--status-draw);
  border-radius: 4px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.draw-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn-small {
  flex: 1;
  border: none;
  padding: 6px;
  border-radius: 3px;
  cursor: pointer;
  color: white;
  font-weight: bold;
}

.btn-small.success {
  background: var(--status-good);
}

.btn-small.danger {
  background: var(--status-bad);
}

.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 950px) {
  .game-area {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 500px;
  }

  .sidebar {
    width: 100%;
    height: auto;
  }

  .moves-container {
    max-height: 200px;
  }

  #board {
    width: 100%;
  }
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: #262421;
}

::-webkit-scrollbar-thumb {
  background: #403d39;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #504d49;
}

/* ===== ONBOARDING MODAL (CENTERED OVERLAY) ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  /* Ensure top */
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  /* Prevent layout interaction */
}

.modal-content {
  background: #262421;
  border: 1px solid #403d39;
  border-radius: 12px;
  padding: 40px;
  max-width: 500px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  position: relative;
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 20px;
  display: block;
}

.modal-title {
  font-size: 1.8rem;
  color: var(--text-bright);
  margin-bottom: 15px;
  font-weight: bold;
}

.modal-text {
  font-size: 1.1rem;
  color: var(--text-main);
  line-height: 1.6;
  margin-bottom: 30px;
}

.modal-accent-cp {
  color: #00f2ff;
  font-weight: bold;
}

.modal-accent-chess {
  color: #ffd700;
  font-weight: bold;
}

.btn-start {
  background: linear-gradient(135deg, var(--status-good), #4a7a1c);
  color: white;
  border: none;
  padding: 14px 40px;
  font-size: 1.2rem;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-transform: uppercase;
}

.btn-start:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(98, 153, 36, 0.4);
}

.btn-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ===== USERNAME SELECTION MODAL ===== */
.username-input-group {
  margin-bottom: 25px;
}

.username-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.15rem;
  background: #1a1816;
  border: 2px solid #403d39;
  border-radius: 8px;
  color: var(--text-bright);
  text-align: center;
  outline: none;
  transition: border-color 0.3s;
  box-sizing: border-box;
  letter-spacing: 0.5px;
}

.username-input:focus {
  border-color: var(--status-good);
  box-shadow: 0 0 12px rgba(98, 153, 36, 0.25);
}

.username-input.input-error {
  border-color: #e74c3c;
}

.username-error {
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 8px;
  margin-bottom: 0;
}

.username-error.hidden {
  display: none;
}

.username-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 6px;
  margin-bottom: 0;
  opacity: 0.7;
}

/* ===== WITHDRAWAL UI ===== */
.btn-withdraw-mini {
  background: var(--pk-primary);
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  transition: 0.2s;
  font-size: 0.9rem;
}

.btn-withdraw-mini:hover {
  background: var(--pk-accent);
  transform: scale(1.1);
}

.withdrawal-form {
  max-width: 400px !important;
  text-align: left !important;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text-bright);
}

.withdrawal-info {
  background: var(--bg-body);
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
}

.info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-row span:first-child {
  color: var(--text-dim);
}

.info-row span:last-child {
  color: var(--text-bright);
  font-weight: 500;
  font-family: monospace;
}

.info-row.vertical {
  flex-direction: column;
  gap: 4px;
}

.wallet-address-detail {
  word-break: break-all;
  font-size: 0.85rem;
  opacity: 0.9;
}

.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.amount-input-wrapper {
  display: flex;
  gap: 10px;
}

.amount-input-wrapper input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-bright);
  padding: 12px;
  border-radius: 6px;
  font-size: 1.1rem;
  font-family: monospace;
}

#btn-max-withdraw {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--pk-accent);
  padding: 0 15px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

#btn-max-withdraw:hover {
  background: var(--bg-highlight);
  border-color: var(--pk-primary);
}

.input-hint {
  display: block;
  margin-top: 5px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.withdrawal-limits {
  border-top: 1px solid var(--border-color);
  padding-top: 15px;
  margin-bottom: 20px;
}

.limit-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.error-box {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--status-bad);
  color: var(--status-bad);
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.modal-footer {
  margin-top: 20px;
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.4;
  text-align: center;
}

/* ===== REWARDS MODAL (Accordion Refined) ===== */
#rewards-modal .modal-content {
  background: rgba(22, 27, 34, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(139, 92, 246, 0.3);
  max-width: 650px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  position: relative;
  animation: modalFadeIn 0.3s ease-out;
  padding: 40px 30px;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.accordion-item {
  margin-bottom: 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(48, 54, 61, 0.2);
  transition: border-color 0.3s;
}

.accordion-item.active {
  border-color: var(--pk-primary);
  background: rgba(48, 54, 61, 0.4);
}

.accordion-header {
  width: 100%;
  padding: 18px 20px;
  background: none;
  border: none;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  text-align: left;
  font-size: 1.1rem;
  font-weight: 600;
  transition: background 0.2s;
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.accordion-header h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-bright);
}

.accordion-icon {
  font-size: 0.8rem;
  transition: transform 0.3s;
  color: var(--pk-accent);
}

.accordion-item.active .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(13, 17, 23, 0.5);
}

.accordion-item.active .accordion-content {
  max-height: 1000px;
}

.inner-content {
  padding: 0 20px 20px 20px;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-main);
}

.rewards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 15px;
  margin-top: 10px;
}

.reward-card {
  background: var(--bg-input);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.reward-card .label {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: block;
}

.reward-card .value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--pk-primary);
}

.rewards-list {
  list-style: none;
  padding: 0;
}

.rewards-list li {
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.rewards-list li:last-child {
  border-bottom: none;
}

.rewards-list li .item-name {
  color: var(--text-main);
}

.rewards-list li .item-value {
  color: var(--pk-accent);
  font-weight: 700;
}

.migration-guarantee {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(139, 92, 246, 0.2));
  border: 1px solid var(--pk-primary);
  padding: 20px;
  border-radius: 12px;
  margin-top: 20px;
  text-align: center;
}

.migration-guarantee h4 {
  color: var(--pk-accent);
  margin-bottom: 10px;
}

.net-pool-info {
  margin-top: 15px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-main);
}

.important-note {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 10px;
}

.close-modal-btn {
  position: absolute;
  top: 15px;
  right: 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  transition: 0.2s;
}

.close-modal-btn:hover {
  color: var(--status-bad);
  transform: rotate(90deg);
}

.rewards-header {
  text-align: center;
  margin-bottom: 25px;
}

.rewards-header h2 {
  font-size: 2rem;
  color: var(--pk-accent);
  margin-bottom: 10px;
}

.rewards-badge {
  display: inline-block;
  background: var(--bg-highlight);
  color: var(--pk-primary);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* ===== BOARD COLOR THEMES ===== */

/* Settings Button (Gear Icon) */
.settings-menu {
  position: relative;
  margin-left: 4px;
}

.settings-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, color 0.2s, background 0.2s;
}

.settings-btn:hover {
  color: var(--text-bright);
  background: var(--bg-highlight);
  transform: rotate(30deg);
}

/* Settings Dropdown */
.settings-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.15s, transform 0.15s;
}

.settings-dropdown.hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

/* Expandable Section Button */
.settings-section-btn {
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}

.settings-section-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.settings-section-btn .chevron {
  margin-left: auto;
  font-size: 1.2rem;
  color: var(--text-dim);
  transition: transform 0.2s;
}

.settings-section-btn.expanded .chevron {
  transform: rotate(90deg);
}

/* Expandable Section Content */
.settings-section-content {
  padding: 8px 16px 12px;
  border-top: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.settings-section-content.hidden {
  display: none;
}

/* Theme Picker (inside settings dropdown) */
.theme-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 4px 0;
}

.theme-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}

.theme-dot:hover {
  transform: scale(1.15);
}

.theme-dot.active {
  border-color: var(--pk-accent);
  box-shadow: 0 0 6px rgba(167, 139, 250, 0.5);
}

/* Each dot shows a split of light/dark colors */
.theme-dot::before,
.theme-dot::after {
  content: '';
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
}

.theme-dot::before {
  left: 0;
}

.theme-dot::after {
  right: 0;
}

/* Dot preview colors */
.theme-dot[data-theme="ice-blue"]::before {
  background: #dce4e8;
}

.theme-dot[data-theme="ice-blue"]::after {
  background: #8baab5;
}

.theme-dot[data-theme="dark-wood"]::before {
  background: #d4a85c;
}

.theme-dot[data-theme="dark-wood"]::after {
  background: #6b4226;
}

.theme-dot[data-theme="green"]::before {
  background: #ebecd0;
}

.theme-dot[data-theme="green"]::after {
  background: #739552;
}

.theme-dot[data-theme="purple"]::before {
  background: #e0d0e8;
}

.theme-dot[data-theme="purple"]::after {
  background: #8877a8;
}

.theme-dot[data-theme="olive"]::before {
  background: #d8e4c0;
}

.theme-dot[data-theme="olive"]::after {
  background: #7a9a50;
}

.theme-dot[data-theme="classic-wood"]::before {
  background: #e8b878;
}

.theme-dot[data-theme="classic-wood"]::after {
  background: #a47040;
}

/* ===== BOARD SQUARE COLOR OVERRIDES ===== */

/* Theme 1: Ice Blue */
[data-board-theme="ice-blue"] .white-1e1d7 {
  background-color: #dce4e8 !important;
}

[data-board-theme="ice-blue"] .black-3c85d {
  background-color: #8baab5 !important;
}

/* Theme 2: Dark Wood */
[data-board-theme="dark-wood"] .white-1e1d7 {
  background: repeating-linear-gradient(95deg,
      #d8c4a8 0px, #d4be9e 3px, #dcc8ac 5px, #d6c0a2 8px, #dac6aa 11px) !important;
}

[data-board-theme="dark-wood"] .black-3c85d {
  background: repeating-linear-gradient(95deg,
      #8b6840 0px, #876438 3px, #8f6c44 5px, #83603a 8px, #8d6a42 11px) !important;
}

/* Theme 3: Green (Chess.com) */
[data-board-theme="green"] .white-1e1d7 {
  background-color: #ebecd0 !important;
}

[data-board-theme="green"] .black-3c85d {
  background-color: #739552 !important;
}

/* Theme 4: Purple */
[data-board-theme="purple"] .white-1e1d7 {
  background-color: #e8e0f0 !important;
}

[data-board-theme="purple"] .black-3c85d {
  background-color: #9688c0 !important;
}

/* Theme 5: Olive Green */
[data-board-theme="olive"] .white-1e1d7 {
  background-color: #d8e4c0 !important;
}

[data-board-theme="olive"] .black-3c85d {
  background-color: #7a9a50 !important;
}

/* Theme 6: Classic Wood */
[data-board-theme="classic-wood"] .white-1e1d7 {
  background: repeating-linear-gradient(92deg,
      #e8c898 0px, #e4c290 3px, #ecd0a0 5px, #e6c694 8px, #eace9e 11px) !important;
}

[data-board-theme="classic-wood"] .black-3c85d {
  background: repeating-linear-gradient(92deg,
      #a47040 0px, #a06c3c 3px, #a87444 5px, #9c6838 8px, #a67242 11px) !important;
}

/* Responsive: smaller dots on small screens */
@media (max-width: 768px) {
  .theme-dot {
    width: 16px;
    height: 16px;
  }
}

/* =========================================================================
   FRIENDS SYSTEM & SIDEBAR REDESIGN
   ========================================================================= */

/* Custom Dropdown Time Selector */
.custom-dropdown {
  position: relative;
  margin-bottom: 20px;
}

.time-selector-toggle {
  width: 100%;
  padding: 12px;
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s;
}

.time-selector-toggle:hover {
  border-color: var(--pk-primary);
}

.time-selector-toggle .caret {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.time-selector-menu {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background-color: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  margin-top: 5px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

.time-selector-menu.hidden {
  display: none;
}

/* Time Control Grid Buttons */
.time-control-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-color: transparent;
  padding: 12px;
}

.time-category {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.time-category:first-child {
  margin-top: 0;
}

.time-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px;
}

.time-btn {
  background-color: #30363d;
  color: var(--text-main);
  border: 1px solid transparent;
  padding: 8px 5px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.time-btn:hover {
  background-color: #3b424a;
}

.time-btn.active {
  background-color: rgba(139, 92, 246, 0.15);
  /* Light purple background */
  border-color: var(--pk-primary);
  color: var(--text-bright);
}

/* Sidebar Lobby Action Buttons */
.lobby-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 15px;
}

.purple-btn {
  background: var(--pk-primary) !important;
  color: white !important;
}

.purple-btn:hover {
  background: var(--pk-accent) !important;
  transform: translateY(-2px);
}

.btn-friend-challenge,
.btn-tourneys {
  background: #21262d;
  color: var(--text-main);
  border: 1px solid var(--border-color);
  width: 100%;
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-friend-challenge:hover,
.btn-tourneys:hover {
  background: #30363d;
  border-color: #8b949e;
}

/* Friend Modal */
.friend-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 15px;
  gap: 10px;
}

.friend-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 15px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.friend-tab.active {
  color: var(--text-bright);
  border-bottom: 2px solid var(--pk-primary);
}

.friend-tab:hover:not(.active) {
  color: var(--text-main);
}

.friends-list-container {
  max-height: 400px;
  overflow-y: auto;
  margin-top: 10px;
}

.friend-item {
  transition: background 0.2s;
}

.friend-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.online-indicator {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-panel);
}

.online-indicator.online {
  background-color: var(--status-good);
}

.online-indicator.offline {
  background-color: var(--text-dim);
}

.badge {
  background: var(--status-bad);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.75rem;
  margin-left: 5px;
}

.btn-challenge {
  width: auto !important;
  max-width: fit-content;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  font-weight: 600;
  transition: opacity 0.2s;
  flex: 0 0 auto;
}

.btn-challenge:hover {
  opacity: 0.8;
}

/* Sidebar state transitions */
.sidebar-lobby {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
}

/* In-game layout constraints */
#sidebar-ingame {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
}

.moves-container {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  /* allows it to grow and shrink */
  min-height: 0;
  /* crucial for flex-shrink to work inside nested flexboxes */
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-panel);
  margin-bottom: 15px;
}

.moves-header {
  flex: 0 0 auto;
  padding: 10px 15px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
  font-weight: bold;
}

.move-history-content {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
}

.game-controls {
  flex: 0 0 auto;
  /* prevents buttons from shrinking */
}