/* ============================================
   PLAY PAGE STYLES - REFACTORED
   ============================================ */

/* 1. LAYOUT & GRID */
body {
  padding-top: var(--header-h);
  overflow: hidden;
}

.main-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: calc(100vh - 60px);
  background: var(--bg-body);
}

.board-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  position: relative;
}

.board-wrapper {
  width: min(90vw, calc(100vh - 100px));
  height: min(90vw, calc(100vh - 100px));
  max-width: 680px;
  max-height: 680px;
  position: relative;
}

/* 2. SIDEBAR */
.sidebar-right {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border-color);
  overflow: hidden;
}

/* 3. PLAYER INFO */
.player-info-container {
  padding: 15px;
  background: var(--bg-sidebar-alt);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.player-details {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 18px;
  color: var(--text-muted);
}

.avatar.online {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-primary);
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.username {
  font-weight: 600;
  color: var(--text-primary);
}

.rating {
  color: var(--accent-primary);
  font-family: "Roboto Mono", monospace;
  font-size: 13px;
  font-weight: 500;
}

/* 4. CLOCK */
.clock {
  font-family: "Roboto Mono", monospace;
  font-size: 24px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--bg-body);
  color: var(--text-primary);
  min-width: 85px;
  text-align: center;
  transition: all 0.2s;
}

.clock.active {
  background: var(--accent-primary);
  color: #000;
}

.clock.low-time {
  animation: clockPulse 0.6s infinite;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

.clock.active.low-time {
  background: #ef4444;
  color: white;
}

@keyframes clockPulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

/* 5. MOVE LIST */
.move-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  overflow: hidden;
  position: relative;
}

.move-list-header {
  padding: 10px 15px;
  background: var(--bg-sidebar-alt);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mode-badge {
  font-family: "Roboto Mono", monospace;
  color: var(--accent-primary);
  font-weight: bold;
  font-size: 12px;
  background: rgba(245, 158, 11, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
}

.move-list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 5px 0;
}

.move-row {
  display: grid;
  grid-template-columns: 35px 1fr 1fr;
  padding: 3px 12px;
  font-size: 14px;
  cursor: pointer;
}

.move-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.move-num {
  color: var(--text-muted);
  font-family: "Roboto Mono", monospace;
}

.move-ply {
  padding: 2px 8px;
  border-radius: 3px;
  color: var(--text-primary);
  font-family: "Roboto Mono", monospace;
  cursor: pointer;
  transition: background 0.15s;
}

.move-ply:hover {
  background: rgba(255, 255, 255, 0.08);
}

.move-ply.active {
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent-primary);
  font-weight: 600;
}

.move-ply.viewing {
  background: rgba(99, 102, 241, 0.25);
  color: #818cf8;
  font-weight: 600;
}

/* Move Navigation Bar */
.move-nav-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  background: var(--bg-sidebar-alt);
  border-top: 1px solid var(--border-color);
}

.nav-btn {
  width: 36px;
  height: 32px;
  border: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  color: var(--text-muted);
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.nav-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.nav-btn:active {
  transform: scale(0.95);
}

/* 6. SIDEBAR BOTTOM (Chat & Tools) */
.sidebar-bottom {
  border-top: 1px solid var(--border-color);
}

.tabs-nav {
  display: flex;
  background: var(--bg-sidebar-alt);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  background: rgba(245, 158, 11, 0.05);
}

.tab-content {
  height: 200px;
  position: relative;
}

.tab-pane {
  display: none;
  height: 100%;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
}

/* Chat */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.chat-input-area {
  padding: 8px;
  border-top: 1px solid var(--border-color);
}

.chat-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}

.chat-input:focus {
  border-color: var(--accent-primary);
}

/* Tools (Game Actions) */
.game-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
}

.action-btn {
  padding: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
}

.action-btn.resign:hover {
  background: var(--error);
  border-color: var(--error);
  color: white;
}

.action-btn.draw:hover {
  background: var(--info);
  border-color: var(--info);
  color: white;
}

/* 7. LOBBY OVERLAY */
.lobby-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3000;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lobby-overlay.hidden {
  display: none;
}

.lobby-card {
  background: var(--bg-sidebar);
  padding: 35px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.lobby-title {
  font-size: 28px;
  background: linear-gradient(to right, #f59e0b, #d97706);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 5px;
}

.lobby-subtitle {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: 14px;
}

/* Time Control Categories */
.tc-categories {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.tc-cat-btn {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-body);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s;
}

.tc-cat-btn.active {
  border-color: var(--accent-primary);
  background: rgba(245, 158, 11, 0.1);
  color: var(--accent-primary);
}

.tc-cat-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
}

/* Time Control Options */
.tc-options {
  margin-bottom: 16px;
}

.tc-group {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.tc-group.active {
  display: flex;
}

.tc-btn {
  padding: 10px 18px;
  border: 1px solid var(--border-color);
  background: var(--bg-body);
  color: var(--text-primary);
  border-radius: 6px;
  cursor: pointer;
  font-family: "Roboto Mono", monospace;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
  min-width: 60px;
}

.tc-btn.active {
  border-color: var(--accent-primary);
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-primary);
}

.tc-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-muted);
}

/* Custom Time Controls */
.custom-tc-inputs {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 5px 0;
}

.custom-input-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.custom-input-group label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.custom-input-group input {
  width: 70px;
  padding: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-body);
  color: var(--text-primary);
  text-align: center;
  border-radius: 6px;
  font-family: "Roboto Mono", monospace;
  font-size: 18px;
  font-weight: 600;
  outline: none;
}

.custom-input-group input:focus {
  border-color: var(--accent-primary);
}

/* Lobby Buttons */
.lobby-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 12px;
}

.lobby-divider::before,
.lobby-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.join-area {
  display: flex;
  gap: 10px;
}

.room-code-input {
  flex: 1;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-body);
  color: white;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-family: "Roboto Mono", monospace;
  font-size: 16px;
  font-weight: 600;
  outline: none;
}

.room-code-input:focus {
  border-color: var(--accent-primary);
}

.btn-join {
  padding: 10px 24px;
  background: var(--bg-sidebar-alt);
  color: white;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-join:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

/* 8. FIRST-MOVE COUNTDOWN BAR */
.first-move-bar {
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  z-index: 2500;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 20px;
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  backdrop-filter: blur(8px);
}

.first-move-label {
  color: var(--accent-primary);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.first-move-progress {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.first-move-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  border-radius: 3px;
  transition: width 0.1s linear;
}

.first-move-timer {
  color: var(--accent-primary);
  font-family: "Roboto Mono", monospace;
  font-weight: 700;
  font-size: 14px;
  min-width: 30px;
  text-align: right;
}

/* 9. DRAW OFFER & REMATCH TOAST */
.draw-offer-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4000;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: var(--text-primary);
  font-weight: 600;
}

.draw-offer-actions {
  display: flex;
  gap: 8px;
}

.draw-accept-btn,
.draw-decline-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  transition: all 0.15s;
}

.draw-accept-btn {
  background: #22c55e;
  color: white;
}

.draw-accept-btn:hover {
  background: #16a34a;
}

.draw-decline-btn {
  background: #ef4444;
  color: white;
}

.draw-decline-btn:hover {
  background: #dc2626;
}

/* 10. GAME TOAST */
.game-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 2000;
  font-size: 14px;
  font-weight: 500;
}

.game-toast.show {
  opacity: 1;
}

/* 11. RATING CHANGE BADGE */
.rating-change-badge {
  font-family: "Roboto Mono", monospace;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
  padding: 4px 12px;
  border-radius: 6px;
  display: inline-block;
}

.rating-change-badge.positive {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.rating-change-badge.negative {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.rating-change-badge.neutral {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

/* RESPONSIVE DESIGN */
@media (max-width: 950px) {
  body {
    overflow-y: auto;
  }

  .main-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 60px);
  }

  .board-area {
    order: 2;
    padding: 5px;
  }

  .board-wrapper {
    width: min(100vw - 10px, 100vw - 10px);
    height: min(100vw - 10px, 100vw - 10px);
  }

  .sidebar-right {
    display: contents;
  }

  #playerInfoTop {
    order: 1;
    border-bottom: 1px solid var(--border-color);
  }

  #playerInfoBottom {
    order: 3;
    border-top: 1px solid var(--border-color);
  }

  .move-list-container {
    order: 5;
    max-height: 200px;
  }

  .sidebar-bottom {
    order: 6;
  }

  .mobile-controls {
    order: 4;
    display: flex;
    justify-content: center;
    background: var(--bg-secondary);
    padding: 10px;
    gap: 20px;
  }
}

/* 12. MODAL STYLES */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

/* Promotion Modal */
.promotion-modal {
  min-width: 280px;
}

.promotion-pieces {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.promotion-piece {
  width: 65px;
  height: 65px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.promotion-piece:hover {
  border-color: var(--accent-primary);
  transform: scale(1.1);
}

/* Game Over Modal */
.game-over-modal {
  min-width: 320px;
  max-width: 400px;
}

.game-over-modal h2 {
  font-size: 28px;
  color: var(--text-primary);
}

.game-over-modal.win h2 {
  color: #22c55e;
}

.game-over-modal.lose h2 {
  color: #ef4444;
}

.game-over-modal.draw h2 {
  color: #f59e0b;
}

/* 13. BUTTONS */
.btn-primary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.btn-secondary {
  background: var(--bg-sidebar-alt);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
}

/* 14. MODE CARD (fallback, may not be used) */
.mode-card {
  transition: all 0.2s;
}

.mode-card.active {
  border-color: var(--accent-primary) !important;
  background: rgba(245, 158, 11, 0.1) !important;
}

.mode-card:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05) !important;
}

/* 15. PIECE ANIMATION */
.piece-animate {
  transition: left 0.2s ease, top 0.2s ease;
}