


/* ===== VARIABLES ===== */
:root {
  /* Colors - Dark Theme (Default) */
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #3498db;
  --success-color: #27ae60;
  --warning-color: #e74c3c;
  --danger-color: #c0392b;
  
  /* Text Colors */
  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
  --text-muted: #95a5a6;
  
  /* Background Colors */
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-glass: rgba(40, 44, 52, 0.95);
  --bg-glass-light: rgba(255, 255, 255, 0.1);
  
  /* Board Colors */
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-light-hover: #ebd5a8;
  --board-dark-hover: #a87e5f;
  
  /* Border & Shadow */
  --border-color: rgba(255, 255, 255, 0.15);
  --border-light: rgba(255, 255, 255, 0.1);
  --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-heavy: 0 8px 30px rgba(0, 0, 0, 0.5);
  
  /* Transitions */
  --transition-fast: 0.1s ease;
  --transition-normal: 0.1s ease;
  --transition-slow: 0.1s ease;
  
  /* Border Radius */
  --radius-small: 8px;
  --radius-medium: 12px;
  --radius-large: 20px;
  --radius-circle: 50%;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* ===== TELEGRAM SPECIFIC VARIABLES ===== */
  /* این متغیرها مخصوص تنظیم موقعیت در تلگرام هستند */
  
  /* موقعیت نوار تاریخچه از بالا */
  --telegram-moves-history-top: 8px;
  
  /* موقعیت بازیکنان بالا از بالا - مقدار اصلاح شده */
  --telegram-top-players-top: 55px;
  
  /* موقعیت بازیکنان پایین از پایین (بالای کنترل‌ها) */
  --telegram-bottom-players-bottom: 70px;
  
  /* موقعیت کنترل‌های بازی از پایین */
  --telegram-controls-bottom: 12px;
  
  /* موقعیت کنترل صدا از پایین */
  --telegram-sound-bottom: 15px;
  
  /* موقعیت کنترل صدا از چپ */
  --telegram-sound-left: 12px;
  
  /* ارتفاع نوار تاریخچه */
  --telegram-moves-history-height: 38px;
  
  /* پدینگ نوار تاریخچه */
  --telegram-moves-history-padding: 6px 12px;
  
  /* عرض نوار تاریخچه */
  --telegram-moves-history-width: calc(100% - 20px);
  
  /* حداکثر عرض نوار تاریخچه */
  --telegram-moves-history-max-width: 450px;
  
  /* حداقل عرض اطلاعات بازیکنان */
  --telegram-player-min-width: 100px;
  
  /* حداکثر عرض اطلاعات بازیکنان */
  --telegram-player-max-width: 140px;
  
  /* پدینگ اطلاعات بازیکنان */
  --telegram-player-padding: 6px 10px;
  
  /* اندازه صفحه شطرنج در تلگرام */
  --telegram-board-size: min(90vw, 90vh - 120px, 450px);
  /* موقعیت صفحه شطرنج از بالا - مقدار جدید */
  --telegram-board-top-offset: -10px;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --primary-color: #3498db;
  --secondary-color: #2980b9;
  --accent-color: #e74c3c;
  
  --text-primary: #2c3e50;
  --text-secondary: #34495e;
  --text-muted: #7f8c8d;
  
  --bg-primary: #ecf0f1;
  --bg-secondary: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.95);
  --bg-glass-light: rgba(0, 0, 0, 0.05);
  
  --border-color: rgba(0, 0, 0, 0.1);
  --border-light: rgba(0, 0, 0, 0.05);
}

/* ===== TELEGRAM APP STYLES ===== */
.telegram-app {
  /* تنظیمات کلی برای تلگرام */
  --telegram-top-players-top: 55px;
  --telegram-board-top-offset: -10px;
}

.telegram-app body {
  /* جلوگیری از اسکرول ناخواسته در تلگرام */
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

/* ===== BASE STYLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  touch-action: manipulation;
}

body {
  position: relative;
  min-height: 100vh;
}

/* ===== SCREENS LAYOUT ===== */
.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-y: auto;
  z-index: 10;
  background: var(--bg-primary);
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ===== CONTAINERS ===== */
.container {
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-large);
  padding: var(--space-xl) var(--space-lg);
  margin: var(--space-md);
  width: calc(100% - var(--space-lg));
  max-width: 450px;
  text-align: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-heavy);
  position: relative;
}

.container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-color), transparent);
  border-radius: var(--radius-large) var(--radius-large) 0 0;
}

/* ===== TYPOGRAPHY ===== */
h1 {
  font-size: clamp(1.8rem, 5vw, 2.2rem);
  margin-bottom: var(--space-lg);
  color: var(--accent-color);
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  margin-bottom: var(--space-md);
  color: var(--accent-color);
  font-weight: 600;
}

h3 {
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
  font-weight: 600;
}

/* ===== FORM ELEMENTS ===== */
.form-group {
  margin-bottom: var(--space-lg);
  text-align: right;
}

label {
  display: block;
  margin-bottom: var(--space-sm);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  background: var(--bg-glass-light);
  color: var(--text-primary);
  font-size: 16px;
  transition: var(--transition-normal);
  -webkit-appearance: none;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--accent-color);
  background: var(--bg-glass);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

input::placeholder {
  color: var(--text-muted);
}

/* ===== BUTTONS ===== */
.btn-primary,
.btn-secondary,
.time-btn {
  padding: var(--space-md) var(--space-lg);
  border: none;
  border-radius: var(--radius-medium);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-normal);
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
}

.btn-primary::before,
.btn-secondary::before,
.time-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: var(--transition-normal);
}

.btn-primary:hover::before,
.btn-secondary:hover::before,
.time-btn:hover::before {
  left: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
  color: white;
  box-shadow: var(--shadow-light);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-medium);
}

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

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-glass-light);
  transform: translateY(-2px);
}

.time-btn {
  background: var(--bg-glass-light);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.time-btn:hover,
.time-btn.active {
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
  color: white;
  transform: translateY(-2px);
}

/* ===== TIME CONTROLS ===== */
.time-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.custom-time {
  margin-top: var(--space-sm);
}

/* ===== GAME SCREEN ===== */
.game-container {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.game-wrapper {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ===== CHESS BOARD RELATIVE CONTAINER ===== */
.chess-board-relative-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 80px;
  padding-bottom: 100px;
  background: #000000 !important;
}

/* ===== MOVES HISTORY - FIXED POSITION ===== */
.moves-history-compact {
  position: absolute;
  top: 1px;
  left: 50%;
  transform: translateX(-50%);
  background: #000000 !important;
  border: 1px solid #1a252f;
  padding: 8px 12px;
  border-radius: 10px;
  height: 45px;
  width: calc(100% - 32px);
  max-width: 500px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 90;
}

.moves-scroll-container {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  height: 100%;
  width: 100%;
  direction: ltr;
  scrollbar-width: thin;
  scrollbar-color: #4a6572 #2c3e50;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  align-items: center;
  position: relative;
}

.moves-history {
  display: flex;
  gap: 6px;
  height: 100%;
  align-items: center;
  padding: 2px 0;
  flex-shrink: 0;
}

.move-record {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.12);
  padding: 5px 10px;
  border-radius: 12px;
  font-size: 0.75em;
  color: #ecf0f1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.2;
  font-family: 'Courier New', monospace;
  font-weight: 600;
  align-items: center;
  justify-content: center;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-record:hover {
  background: rgba(52, 152, 219, 0.4);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.move-record.current {
  background: #e74c3c;
  color: white;
  box-shadow: 0 2px 8px rgba(231, 76, 60, 0.5);
  border-color: #c0392b;
  transform: scale(1.05);
}

.moves-scroll-container::-webkit-scrollbar {
  height: 4px;
}

.moves-scroll-container::-webkit-scrollbar-track {
  background: var(--bg-glass-light);
  border-radius: 2px;
  margin: 0 8px;
}

.moves-scroll-container::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.moves-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--primary-color);
}

/* ===== PLAYER INFO - FIXED POSITION OUTSIDE BOARD ===== */
.player-info-corner {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-medium);
  z-index: 100;
  font-size: 0.9em;
  box-shadow: var(--shadow-heavy);
  backdrop-filter: blur(20px);
  transition: var(--transition-normal);
  min-width: 120px;
  max-width: 200px;
}



.player-top-right {
  top: 110px;
  left: 250px;
  animation: slideInFromTop 0.6s ease-out;
  background: #000000 !important;
}
 .player-top-left {
    top: 70px;
    left: 250px;
    animation: slideInFromTop 0.6s ease-out;
    background: #000000 !important;
  }

.player-bottom-left {
  bottom: 150px;
  
  right: 290px !important;
  animation: slideInFromBottom 0.6s ease-out;
  background: #000000 !important;
}

.player-bottom-right {
  bottom: 190px;
  right: 310px;
  animation: slideInFromBottom 0.6s ease-out;
  background: #000000 !important;
}

.player-info-corner::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success-color);
  margin-left: 4px;
  animation: fadeInOut 2s infinite;
}

.player-top-left::before,
.player-bottom-left::before {
  background: #3498db;
}

.player-top-right::before,
.player-bottom-right::before {
  background: #2c3e50;
}

.player-name-small {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.player-info-corner.active-turn {
  border-color: var(--accent-color);
  box-shadow: 0 0 15px rgba(52, 152, 219, 0.4);
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
}

.player-info-corner.active-turn .player-name-small {
  color: white;
}

.player-info-corner.active-turn .timer-display-small {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  color: white;
}

/* ===== TIMER DISPLAY ===== */
.timer-display-small {
  font-family: 'Courier New', monospace;
  font-size: 1em;
  font-weight: 700;
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-small);
  background: linear-gradient(135deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.5));
  transition: var(--transition-normal);
  min-width: 60px;
  text-align: center;
  border: 1px solid var(--border-light);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.3);
}

.timer-display-small.active {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: white;
  box-shadow: 0 0 15px rgba(231, 76, 60, 0.7);
  animation: pulse 1.5s infinite;
  border-color: rgba(255, 255, 255, 0.3);
}

.timer-display-small.low-time {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: white;
  animation: blink 0.8s infinite;
  border-color: rgba(255, 255, 255, 0.4);
}

.timer-display-small.timer-critical {
  background: linear-gradient(135deg, #e74c3c, #c0392b) !important;
  color: white !important;
  animation: criticalBlink 0.5s infinite !important;
  border-color: rgba(255, 255, 255, 0.5) !important;
}

/* ===== CHESS BOARD WITH COORDS ===== */
.chess-board-with-coords {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 70px 0 90px 0;
  position: relative;
  margin-top: -20px !important;
  margin-bottom: 40px !important;
}


.chess-board-container {
  position: relative;
  display: inline-block;
  width: 100%; /* اضافه شده */
  max-width: min(100vw, 100vh - 150px, 700px); /* محدودیت حداکثر اندازه */
}
#chessBoard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100% !important; /* عرض کامل کانتینر */
  height: auto !important; /* ارتفاع خودکار */
  aspect-ratio: 1 / 1; /* نسبت مربعی حفظ شود */
  border: 2px solid var(--secondary-color);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-heavy);
  touch-action: none;
  background: var(--secondary-color);
  position: relative;
}

/* ===== BOARD SQUARES ===== */
.square {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  transition: var(--transition-fast);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  z-index: 1;
}

.square.light {
  background-color: var(--board-light);
}

.square.dark {
  background-color: var(--board-dark);
}

.square.selected {
  background-color: var(--accent-color) !important;
  transform: scale(0.95);
  z-index: 4 !important;
}

.square.valid-move::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-circle);
  background: rgba(46, 204, 113, 0.6);
  border: 2px solid var(--success-color);
  z-index: 3;
}

.square.check {
  background-color: rgba(255, 0, 0, 0.4) !important;
  animation: checkPulse 1.5s infinite;
  z-index: 5 !important;
}

.square.pending-move-from {
  background: rgba(255, 248, 225, 0.7) !important;
  border: 2px solid rgba(255, 215, 0, 0.7);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
  position: relative;
}

.square.pending-move-to {
  background: rgba(255, 243, 205, 0.8) !important;
  border: 2px solid rgba(255, 193, 7, 0.8);
  box-shadow: 0 0 15px rgba(255, 193, 7, 0.5);
  position: relative;
}

.square.last-move-from {
  background: rgba(255, 248, 225, 0.7) !important;
  border: 2px solid rgba(255, 215, 0, 0.7);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
  position: relative;
}

.square.last-move-to {
  background: rgba(255, 243, 205, 0.8) !important;
  border: 2px solid rgba(255, 193, 7, 0.8);
  box-shadow: 0 0 15px rgba(255, 193, 7, 0.5);
  position: relative;
}

@keyframes softPulse {
  0% { opacity: 0.9; }
  50% { opacity: 1; }
  100% { opacity: 0.9; }
}

.square.pending-move-from,
.square.pending-move-to {
  animation: softPulse 2s ease-in-out infinite;
}

/* ===== CHESS PIECES ===== */
.piece {
  width: 85%;
  height: 85%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 2;
  position: relative;
  transition: var(--transition-fast);
  cursor: pointer;
  filter: drop-shadow(2px 2px 3px rgba(0,0,0,0.3));
}

.piece:hover {
  transform: scale(1.1);
}

.piece.dragging {
  transform: scale(1.1);
  z-index: 1000;
}

/* ===== BOARD COORDINATES - FIXED ===== */
 /* مختصات اعداد (سمت چپ و راست) */
.coordinate {
  position: absolute;
  font-size: 10px !important; /* کاهش سایز فونت */
  font-weight: 600;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0.5px 0.5px 1px rgba(0,0,0,0.8);
}
/* مختصات اعداد (گوشه بالا راست هر خانه) */
.coordinate.number {
  top: 1px !important;
  right: 1px !important; /* تغییر از left به right */
  left: auto !important;
  bottom: auto !important;
}
/* مختصات حروف (گوشه پایین راست هر خانه) */
.coordinate.letter {
  bottom: 1px !important;
  left: 1px !important; /* تغییر موقعیت به راست */
  right: auto !important;
  top: auto !important;
}
/* رنگ‌بندی مختصات بر اساس رنگ خانه */
.square.light .coordinate {
  color: var(--board-dark);
  text-shadow: 0.5px 0.5px 1px rgba(255,255,255,0.8);
}

.square.dark .coordinate {
  color: var(--board-light);
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

/* ===== TELEGRAM SPECIFIC STYLES ===== */
body.telegram-app .chess-board-container {
  width: 95% !important;
  max-width: 500px !important;
}
body.telegram-app #chessBoard {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 1 / 1 !important;
  max-width: 500px !important;
  max-height: 500px !important;
}
/* ===== GAME CONTROLS BOTTOM ===== */
.game-controls-bottom {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border-radius: var(--radius-medium);
  border: 1px solid var(--border-color);
  width: calc(100% - 32px);
  max-width: 300px;
  z-index: 99;
  background: #000000 !important;
  box-shadow: var(--shadow-medium);
}

.control-btn-small {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-small);
  font-size: 0.7em;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-normal);
  color: white;
  background: var(--bg-glass-light);
  border: 1px solid var(--border-light);
  position: relative;
  touch-action: manipulation;
  min-height: 32px;
}

.control-btn-small:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-light);
}

.control-btn-small.resign {
  background: linear-gradient(135deg, var(--warning-color), var(--danger-color));
}

.control-btn-small.chat {
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
}

.control-btn-small.history {
  background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}

.control-btn-small.flip {
  background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
}

.control-btn-small:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.control-btn-small:disabled:hover {
  transform: none;
  box-shadow: none;
}

.control-btn-small .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: linear-gradient(135deg, var(--warning-color), var(--danger-color));
  color: white;
  border-radius: var(--radius-circle);
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5em;
  font-weight: bold;
  border: 1px solid var(--secondary-color);
  box-shadow: var(--shadow-light);
}

/* ===== SOUND CONTROLS ===== */
.sound-controls {
  position: fixed;
  bottom: 12px;
  left: 12px;
  z-index: 1000;
  display: none;
}
/* نمایش دکمه فقط در صفحه بازی */
#gameScreen.active ~ .sound-controls {
    display: block;
}
/* استایل‌های چت صوتی */
.sound-toggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2em;
    color: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.sound-toggle:hover {
  transform: scale(1.1);
}

.sound-toggle.muted {
  opacity: 0.7;
}
.sound-toggle.voice-chat-enabled {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    box-shadow: 0 0 15px rgba(39, 174, 96, 0.5);
}

.sound-toggle.voice-chat-recording {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    box-shadow: 0 0 20px rgba(231, 76, 60, 0.7);
    animation: pulse-recording 1.5s infinite;
}

.sound-toggle.voice-chat-playing {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.5);
}
.sound-toggle.voice-chat-disabled {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}

@keyframes pulse-recording {
    0% { transform: scale(1); box-shadow: 0 0 20px rgba(231, 76, 60, 0.7); }
    50% { transform: scale(1.05); box-shadow: 0 0 30px rgba(231, 76, 60, 0.9); }
    100% { transform: scale(1); box-shadow: 0 0 20px rgba(231, 76, 60, 0.7); }
}

/* ===== CONNECTION STATUS ===== */
.connection-status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  transition: all 0.3s ease;
}

.connection-status.connected {
  background: #27ae60;
  box-shadow: 0 0 6px rgba(39, 174, 96, 0.5);
}

.connection-status.disconnected {
  background: #e74c3c;
  box-shadow: 0 0 6px rgba(231, 76, 60, 0.5);
}

.player-name-disconnected {
  color: #e74c3c !important;
  text-decoration: line-through;
  opacity: 0.7;
}

/* ===== MODALS ===== */
.glass-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-normal);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.glass-modal.active {
  opacity: 1;
  visibility: visible;
}

.glass-modal-content {
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-large);
  padding: var(--space-lg);
  color: var(--text-primary);
  max-width: 450px;
  width: 90%;
  box-shadow: var(--shadow-heavy);
  transform: scale(0.9);
  transition: var(--transition-normal);
  backdrop-filter: blur(20px);
}

.glass-modal.active .glass-modal-content {
  transform: scale(1);
}

.glass-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-light);
}

.glass-modal-header h3 {
  margin: 0;
  font-size: 1.3em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.glass-modal-close {
  background: var(--bg-glass-light);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-size: 1.5em;
  cursor: pointer;
  padding: 0;
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-circle);
  transition: var(--transition-normal);
}

.glass-modal-close:hover {
  background: var(--accent-color);
  color: white;
  transform: rotate(90deg);
}

.glass-modal-body {
  margin-bottom: var(--space-md);
}

.glass-modal-footer {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.glass-modal-btn {
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-small);
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  transition: var(--transition-normal);
}

.glass-modal-btn.primary {
  background: linear-gradient(135deg, var(--accent-color), var(--primary-color));
  color: white;
}

.glass-modal-btn.secondary {
  background: var(--bg-glass-light);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.glass-modal-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-light);
}

/* ===== CHAT MODAL ===== */
.chat-messages-container {
  height: 250px;
  overflow-y: auto;
  background: var(--bg-glass-light);
  border-radius: var(--radius-medium);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  border: 1px solid var(--border-light);
  scrollbar-width: thin;
  scrollbar-color: var(--accent-color) transparent;
}

.chat-messages-container::-webkit-scrollbar {
  width: 6px;
}

.chat-messages-container::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 3px;
}

.chat-messages-container::-webkit-scrollbar-thumb {
  background: var(--accent-color);
  border-radius: 3px;
}

.chat-message {
  margin-bottom: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-medium);
  background: var(--bg-glass-light);
  font-size: 0.9em;
  border: 1px solid var(--border-light);
  transition: var(--transition-normal);
}

.chat-message:hover {
  background: rgba(0,0,0,0.5);
  transform: translateX(5px);
}

.chat-message.own {
  background: linear-gradient(135deg, rgba(52, 152, 219, 0.25), rgba(41, 128, 185, 0.25));
  text-align: left;
  border: 1px solid rgba(52, 152, 219, 0.3);
}

.message-sender {
  font-weight: bold;
  font-size: 0.85em;
  margin-bottom: 4px;
  color: var(--accent-color);
}

.chat-message.own .message-sender {
  color: var(--success-color);
}

.message-text {
  margin-bottom: 4px;
  line-height: 1.4;
  color: var(--text-primary);
}

.message-time {
  font-size: 0.75em;
  color: var(--text-muted);
  text-align: left;
}

.chat-input-container {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.chat-input-container input {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-medium);
  background: rgba(0,0,0,0.5);
  color: var(--text-primary);
  font-size: 0.9em;
  transition: var(--transition-normal);
}

.chat-input-container input:focus {
  outline: none;
  border-color: var(--accent-color);
  background: rgba(0,0,0,0.5);
}

/* ===== GAME OVER SCREEN ===== */
#gameOverScreen {
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(20px);
}

#gameOverScreen .container {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border: 2px solid var(--border-color);
  border-radius: var(--radius-large);
  padding: var(--space-xl);
  max-width: 500px;
  backdrop-filter: blur(25px);
}

.game-result {
  font-size: 1.3rem;
  margin: var(--space-lg) 0;
  padding: var(--space-md);
  background: var(--bg-glass-light);
  border-radius: var(--radius-medium);
  text-align: center;
}

.rematch-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin: var(--space-lg) 0;
}

.rematch-status {
  text-align: center;
  margin-top: var(--space-md);
  padding: var(--space-sm);
  background: var(--bg-glass-light);
  border-radius: var(--radius-small);
  font-size: 0.9rem;
}

.result-text {
  font-size: 1.5em;
  font-weight: bold;
  margin-bottom: var(--space-sm);
  color: var(--success-color);
}

.reason-text {
  font-size: 1.1em;
  color: var(--text-muted);
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
  0% { 
    opacity: 1;
    transform: scale(1);
  }
  50% { 
    opacity: 0.7;
    transform: scale(1.1);
  }
  100% { 
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.7; }
}

@keyframes checkPulse {
  0% { background-color: rgba(255, 0, 0, 0.4); }
  50% { background-color: rgba(255, 0, 0, 0.7); }
  100% { background-color: rgba(255, 0, 0, 0.4); }
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

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

@keyframes slideInFromTop {
  0% {
    opacity: 0;
    transform: translateY(-20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInFromBottom {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes glow {
  0%, 100% { 
    box-shadow: 0 0 5px rgba(52, 152, 219, 0.5);
  }
  50% { 
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.8), 0 0 30px rgba(52, 152, 219, 0.6);
  }
}

@keyframes criticalBlink {
  0%, 50% { 
    opacity: 1;
    transform: scale(1);
  }
  51%, 100% { 
    opacity: 0.7;
    transform: scale(1.05);
  }
}

/* ===== LOADING ===== */
.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--bg-glass-light);
  border-top: 4px solid var(--accent-color);
  border-radius: var(--radius-circle);
  animation: spin 1s linear infinite;
  margin: var(--space-lg) auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ===== NOTIFICATIONS ===== */
.notification-modal {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-medium);
  border: 1px solid var(--border-color);
  z-index: 3000;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-heavy);
  text-align: center;
  max-width: 90%;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-normal);
}

.notification-modal.show {
  opacity: 1;
  visibility: visible;
}

/* ===== TELEGRAM SPECIFIC STYLES - USING VARIABLES ===== */
.telegram-app .chess-board-relative-container {
  padding-top: 0;
  padding-bottom: 0;
  justify-content: center;
  position: relative;
  min-height: 100vh;
}

/* نوار تاریخچه - بالاترین موقعیت */
.telegram-app .moves-history-compact {
  position: absolute;
  top: var(--telegram-moves-history-top);
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  border: 1px solid #1a252f;
  padding: var(--telegram-moves-history-padding);
  border-radius: 8px;
  height: var(--telegram-moves-history-height);
  width: var(--telegram-moves-history-width);
  max-width: var(--telegram-moves-history-max-width);
  z-index: 100;
}

/* بازیکنان بالا - پایین‌تر از نوار تاریخچه */
.telegram-app .player-top-left {
  position: absolute;
  top: var(--telegram-top-players-top);
  left: 8px;
  z-index: 95;
  min-width: var(--telegram-player-min-width);
  max-width: var(--telegram-player-max-width);
  padding: var(--telegram-player-padding);
}

.telegram-app .player-top-right {
  position: absolute;
  top: var(--telegram-top-players-top);
  right: 8px;
  z-index: 95;
  min-width: var(--telegram-player-min-width);
  max-width: var(--telegram-player-max-width);
  padding: var(--telegram-player-padding);
}

/* صفحه شطرنج - دقیقاً در مرکز */
.telegram-app .chess-board-with-coords {
  position: absolute;
  top: calc(50% + var(--telegram-board-top-offset));
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 50;
  width: 100%;
  display: flex;
  justify-content: center;
}

/* بازیکنان پایین - بالاتر از کنترل‌ها و زیر صفحه شطرنج */
.telegram-app .player-bottom-left {
  position: absolute;
  bottom: var(--telegram-bottom-players-bottom);
  left: 8px !important; /* تغییر به auto */
  right: auto !important; /* اضافه کردن right */
  z-index: 95;
  min-width: var(--telegram-player-min-width);
  max-width: auto !important; /* تغییر به none */
  padding: var(--telegram-player-padding);
}

.telegram-app .player-bottom-right {
  position: absolute;
  bottom: var(--telegram-bottom-players-bottom);
  right: 8px;
  z-index: 95;
  min-width: var(--telegram-player-min-width);
  max-width: var(--telegram-player-max-width);
  padding: var(--telegram-player-padding);
}

/* کنترل‌های بازی - پایین‌ترین المان */
.telegram-app .game-controls-bottom {
  position: absolute;
  bottom: var(--telegram-controls-bottom);
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  width: var(--telegram-moves-history-width);
  max-width: 300px;
}

/* تنظیمات صفحه شطرنج برای تلگرام */
.telegram-app #chessBoard {
  width: var(--telegram-board-size) !important;
  height: var(--telegram-board-size) !important;
}

/* کنترل صدا */
.telegram-app .sound-controls {
  position: fixed;
  bottom: var(--telegram-sound-bottom);
  left: var(--telegram-sound-left);
  z-index: 1000;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablets */
@media (max-width: 768px) {
  .chess-board-relative-container {
    padding-top: 70px;
    padding-bottom: 80px;
  }
  
  .moves-history-compact {
    height: 40px;
    padding: 6px 10px;
    width: calc(100% - 24px);
  }
  
  .move-record {
    padding: 4px 8px;
    font-size: 0.7em;
    max-width: 90px;
  }
  
  .player-info-corner {
    min-width: 110px;
    max-width: 140px;
    padding: 6px 10px;
    font-size: 0.85em;
  }
  
  .player-name-small {
    max-width: 70px;
    font-size: 0.85em;
  }
  
  .timer-display-small {
    font-size: 0.9em;
    min-width: 55px;
    padding: 5px 8px;
  }
  
  .chess-board-with-coords {
    margin: 60px 0 60px 0;
  }
  
  #chessBoard {
    width: min(92vw, 92vh - 220px, 450px);
    height: min(92vw, 92vh - 220px, 450px);
  }
  
  .game-controls-bottom {
    max-width: 280px;
    padding: 6px;
  }
  
  .control-btn-small {
    padding: 6px 8px;
    min-height: 30px;
    font-size: 0.65em;
  }
  
  /* تنظیمات تلگرام برای تبلت */
  .telegram-app .player-top-left,
  .telegram-app .player-top-right {
    top: 50px;
  }
  
  .telegram-app .player-bottom-left,
  .telegram-app .player-bottom-right {
    bottom: 65px;
    max-width: 200px;
    width: auto;
  }
  
  .telegram-app .game-controls-bottom {
    bottom: 10px;
  }
}

/* Mobile Phones */
@media (max-width: 480px) {
  .chess-board-relative-container {
    padding-top: 60px;
    padding-bottom: 70px;
  }
  
  .moves-history-compact {
    height: 35px;
    padding: 5px 8px;
    width: calc(100% - 16px);
  }
  
  .move-record {
    padding: 3px 6px;
    font-size: 0.65em;
    max-width: 80px;
  }
  
  .player-info-corner {
    min-width: 100px;
    max-width: 120px;
    padding: 5px 8px;
    font-size: 0.8em;
  }
  
  .player-top-left,
  .player-top-right {
    top: 1px;
  }
  
  .player-bottom-left,
  .player-bottom-right {
    bottom: 50px;
     max-width: 200px;
    width: auto;
  }
  
  .player-name-small {
    max-width: 60px;
    font-size: 0.8em;
  }
  
  .timer-display-small {
    font-size: 0.85em;
    min-width: 50px;
    padding: 4px 6px;
  }
  
  .chess-board-with-coords {
    margin: 50px 0 50px 0;
  }
  
  #chessBoard {
    width: min(95vw, 95vh - 200px, 400px);
    height: min(95vw, 95vh - 200px, 400px);
  }
  
  .game-controls-bottom {
    max-width: 260px;
    padding: 5px;
    gap: 4px;
  }
  
  .control-btn-small {
    padding: 5px;
    border-radius: var(--radius-circle);
    width: 35px;
    height: 35px;
    justify-content: center;
  }
  
  .control-btn-small span {
    display: none;
  }
  
  .sound-controls {
    bottom: 8px;
    left: 8px;
  }
  
  .sound-toggle {
    width: 35px;
    height: 35px;
    font-size: 0.9em;
  }
  
  /* تنظیمات تلگرام برای موبایل */
  .telegram-app .moves-history-compact {
    height: 35px;
    padding: 5px 8px;
    top: 5px;
  }
  
  .telegram-app .player-top-left,
  .telegram-app .player-top-right {
    top: 45px;
    min-width: 90px;
    max-width: 120px;
    padding: 4px 6px;
  }
  
  .telegram-app .player-bottom-left,
  .telegram-app .player-bottom-right {
    bottom: 50px;
    min-width: 90px;
    max-width: 200px;
    width: auto;
    padding: 4px 6px;
  }
  
  .telegram-app #chessBoard {
    width: min(90vw, 90vh - 120px, 400px) !important;
    height: min(90vw, 90vh - 120px, 400px) !important;
  }
  
  .telegram-app .game-controls-bottom {
    bottom: 8px;
  }
  
  .telegram-app .sound-controls {
    bottom: 10px;
    left: 10px;
  }
}

/* Small Mobile Phones */
@media (max-width: 360px) {
  .moves-history-compact {
    height: 32px;
    padding: 4px 6px;
  }
  
  .move-record {
    padding: 2px 4px;
    font-size: 0.6em;
    max-width: 70px;
  }
  
  .player-info-corner {
    min-width: 90px;
    max-width: 110px;
    padding: 4px 6px;
  }
  
  .player-name-small {
    max-width: 50px;
    font-size: 0.75em;
  }
  
  .timer-display-small {
    min-width: 45px;
    font-size: 0.8em;
  }
  
  .game-controls-bottom {
    max-width: 240px;
  }
  
  .control-btn-small {
    width: 32px;
    height: 32px;
  }
}

/* Landscape Orientation */
@media (max-height: 600px) and (orientation: landscape) {
  .chess-board-relative-container {
    padding-top: 60px;
    padding-bottom: 60px;
  }
  
  .moves-history-compact {
    height: 35px;
    margin-bottom: 5px;
  }
  
  .player-info-corner {
    padding: 4px 8px;
    font-size: 0.8em;
  }
  
  .player-bottom-left,
  .player-bottom-right {
    bottom: 45px;
max-width: 200px;
    width: auto;
  }
  
  .chess-board-with-coords {
    margin: 40px 0 40px 0;
  }
  
  #chessBoard {
    width: min(80vh, 80vw) !important;
    height: min(80vh, 80vw) !important;
  }
  
  .game-controls-bottom {
    bottom: 1px;
    max-width: 280px;
  }
}

/* High DPI Screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .piece {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Print Styles */
@media print {
  .game-controls-bottom,
  .sound-controls,
  .glass-modal {
    display: none !important;
  }
  
  .screen {
    position: static;
    display: block !important;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark mode preference */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

/* Light mode preference */
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
  }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-transparency: reduce) {
  .glass-modal-content,
  .container,
  .player-info-corner {
    backdrop-filter: none;
    background: var(--bg-secondary);
  }
}

/* Focus styles for keyboard navigation */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --border-color: #ffffff;
    --border-light: #cccccc;
  }
  
  .glass-modal-content,
  .container {
    border-width: 2px;
  }
}

/* Voice Chat Styles */
.voice-chat-enabled {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%) !important;
    box-shadow: 0 0 12px rgba(39, 174, 96, 0.5) !important;
}

.voice-chat-recording {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%) !important;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.7) !important;
    animation: pulse-recording 1.5s infinite !important;
}

.voice-chat-playing {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%) !important;
    box-shadow: 0 0 12px rgba(52, 152, 219, 0.5) !important;
}

.voice-chat-disabled {
    background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%) !important;
}

@keyframes pulse-recording {
    0% { transform: scale(1); box-shadow: 0 0 15px rgba(231, 76, 60, 0.7); }
    50% { transform: scale(1.05); box-shadow: 0 0 25px rgba(231, 76, 60, 0.9); }
    100% { transform: scale(1); box-shadow: 0 0 15px rgba(231, 76, 60, 0.7); }
}

.voice-chat-notification {
    position: fixed;
    top: 60px;
    left: 12px;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    z-index: 1000;
    font-size: 0.75em;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 3px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
}

.voice-chat-status {
    position: fixed;
    bottom: 60px;
    left: 12px;
    background: rgba(44, 62, 80, 0.9);
    color: white;
    padding: 6px 10px;
    border-radius: 5px;
    font-size: 0.65em;
    border: 1px solid rgba(255,255,255,0.2);
    z-index: 999;
}

/* هایلایت premove (آبی) */
.square.premove-from {
    background: rgba(52, 152, 219, 0.6) !important;
    border: 2px solid rgba(52, 152, 219, 0.8) !important;
    box-shadow: 0 0 12px rgba(52, 152, 219, 0.4) !important;
    position: relative;
    z-index: 3;
}

.square.premove-to {
    background: rgba(41, 128, 185, 0.7) !important;
    border: 2px solid rgba(41, 128, 185, 0.9) !important;
    box-shadow: 0 0 15px rgba(41, 128, 185, 0.5) !important;
    position: relative;
    z-index: 3;
}

/* انیمیشن برای premove */
@keyframes premovePulse {
    0% { opacity: 0.8; }
    50% { opacity: 1; }
    100% { opacity: 0.8; }
}

.square.premove-from,
.square.premove-to {
    animation: premovePulse 2s ease-in-out infinite;
}

/* نشانگر وضعیت premove در UI */
.pmove-indicator {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.75em;
    z-index: 1000;
    box-shadow: 0 3px 12px rgba(52, 152, 219, 0.4);
}

/* هندل تغییر سایز - مخفی شده */
.resize-handle {
  display: none !important;
}

#resizeHandle {
  display: none !important;
}

/* استایل‌های اضافی برای مدیریت بهتر نوار تاریخچه */
.moves-scroll-container::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 15px;
  background: linear-gradient(90deg, transparent, var(--secondary-color));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.moves-scroll-container.scrollable::after {
  opacity: 1;
}
// در بخش style.textContent در انتهای فایل، این استایل‌ها را اضافه کنید:

/* 🔥 استایل‌های جدید برای سیستم پایگاه داده و احراز هویت */
.connection-status {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
}

.connection-status.connected {
    background: #27ae60;
}

.connection-status.disconnected {
    background: #e74c3c;
}

.player-name-disconnected {
    color: #e74c3c !important;
    text-decoration: line-through;
}

/* استایل‌های مودال بازی‌های فعال */
.active-games-list {
    max-height: 300px;
    overflow-y: auto;
    margin: 15px 0;
}

.active-games-list::-webkit-scrollbar {
    width: 8px;
}

.active-games-list::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

.active-games-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 4px;
}

.active-games-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.5);
}

/* استایل برای دکمه بازگشت در حالت مشاهده */
#viewOnlyReturnBtn {
    position: fixed;
    top: 70px;
    left: 10px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: 600;
    z-index: 10001;
    box-shadow: 0 3px 10px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

#viewOnlyReturnBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.4);
}

/* استایل برای نمایش وضعیت کاربر */
.user-status-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(52, 152, 219, 0.9);
    color: white;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.8em;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.user-status-indicator.guest {
    background: rgba(155, 89, 182, 0.9);
}

.user-status-indicator.telegram {
    background: rgba(46, 204, 113, 0.9);
}
/* در بخش CSS موجود اضافه کنید */
#manualReconnectBtn {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.connection-status {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
}

.connection-status.connected {
    background: #27ae60;
    animation: none;
}

.connection-status.disconnected {
    background: #e74c3c;
    animation: pulse 1s infinite;
}

.reconnect-status {
    background: rgba(243, 156, 18, 0.2);
    border: 1px solid #f39c12;
    border-radius: 5px;
    padding: 10px;
    margin: 10px 0;
    text-align: center;
    color: #f39c12;
}
/* در فایل CSS خود اضافه کنید */
.disconnect-modal {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.disconnect-modal.fade-out {
    opacity: 0;
    transform: scale(0.9);
}

.promotion-overlay {
    transition: opacity 0.3s ease;
}

.promotion-overlay.fade-out {
    opacity: 0;
}










.piece.check-glow {
    filter: drop-shadow(0 0 4px #ff4444) 
            drop-shadow(0 0 8px #ff4444)
            drop-shadow(0 0 12px #ff4444);
    /* یا از box-shadow با pseudo-element استفاده کنید */
}

/* روش جایگزین با استفاده از box-shadow */
.piece.check-glow::after {
    content: "";
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 50%;
    background: rgba(255, 68, 68, 0.4);
    box-shadow: 0 0 8px 2px rgba(255, 68, 68, 0.7);
    z-index: -1;
    animation: pulse-glow 1s ease-in-out infinite alternate;
}

@keyframes pulse-glow {
    from {
        opacity: 0.4;
        transform: scale(1);
    }
    to {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

/* اطمینان از positioning نسبی برای piece */
.piece {
    position: relative;
    z-index: 1;
}





/* اضافه کردن به استایل‌ها */
.connection-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.connection-indicator.connected {
    background: rgba(39, 174, 96, 0.9);
    color: white;
    border: 1px solid #27ae60;
}

.connection-indicator.disconnected {
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border: 1px solid #e74c3c;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}
.disconnect-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.85);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 10000;
            backdrop-filter: blur(10px);
        }
        
        .disconnect-modal-content {
            background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
            padding: 30px;
            border-radius: 20px;
            text-align: center;
            color: white;
            max-width: 400px;
            width: 90%;
            border: 2px solid rgba(255,255,255,0.1);
            box-shadow: 0 20px 40px rgba(0,0,0,0.5);
        }
        
        .player-name-disconnected {
            color: #e74c3c !important;
            text-decoration: line-through;
        }
        
        .connection-status {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 8px;
        }
        
        .connection-status.connected {
            background: #27ae60;
        }
        
        .connection-status.disconnected {
            background: #e74c3c;
        }

        @keyframes telegramNotificationSlide {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-8px); /* از 20px به 8px کاهش یافت */
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes telegramNotificationSlideOut {
    0% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-8px); /* از 20px به 8px کاهش یافت */
    }
}
        
        /* بهبود استایل‌های صفحه پایان بازی برای تلگرام */
        #gameOverScreen .btn-primary,
        #gameOverScreen .btn-secondary {
            min-height: 55px !important;
            font-size: 1.1rem !important;
            font-weight: 600 !important;
            border: none !important;
            border-radius: 12px !important;
            cursor: pointer !important;
            transition: all 0.3s ease !important;
            width: 100% !important;
            margin: 8px 0 !important;
            touch-action: manipulation !important;
            -webkit-tap-highlight-color: transparent !important;
            position: relative !important;
            z-index: 100 !important;
        }
        
        #gameOverScreen .btn-primary {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%) !important;
            color: white !important;
            box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4) !important;
        }
        
        #gameOverScreen .btn-secondary {
            background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%) !important;
            color: white !important;
            box-shadow: 0 4px 15px rgba(149, 165, 166, 0.4) !important;
        }
        
        #gameOverScreen .btn-primary:active,
        #gameOverScreen .btn-secondary:active {
            transform: scale(0.98) !important;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
        }
        
        /* بهبود display برای تلگرام */
        #gameOverScreen.active {
            display: flex !important;
            z-index: 1000 !important;
        }
        
        #gameOverScreen .container {
            z-index: 1001 !important;
            position: relative !important;
        }

        /* استایل‌های جدید برای نشانگر ربات */
        .robot-indicator {
            position: fixed;
            top: 80px; /* پایین‌تر از عناصر بالایی */
            right: 15px;
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            color: white;
            padding: 8px;
            border-radius: 50%;
            font-size: 1.2em;
            z-index: 500; /* پایین‌تر از نوار حرکات */
            box-shadow: 0 2px 8px rgba(0,0,0,0.3);
            border: 2px solid rgba(255,255,255,0.3);
            display: flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            backdrop-filter: blur(10px);
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .robot-indicator:hover {
            transform: scale(1.1);
            box-shadow: 0 4px 15px rgba(52, 152, 219, 0.5);
        }

        /* اطمینان از عدم تداخل با عناصر دیگر */
        .timer-display-small, .moves-scroll-container {
            z-index: 600; /* بالاتر از نشانگر ربات */
        }

 /* استایل‌های مودال جمع‌وجور */
    @media (max-width: 480px) {
        .robot-modal-container {
            max-width: 95vw !important;
            padding: 15px !important;
        }
        
        .levels-grid-compact {
            grid-template-columns: repeat(5, 1fr) !important;
            gap: 6px !important;
        }
        
        .robot-level-btn-compact {
            padding: 10px 4px !important;
            min-height: 50px !important;
            font-size: 0.8rem !important;
        }
        
        .robot-level-btn-compact div:first-child {
            font-size: 1.1em !important;
        }
        
        h3 {
            font-size: 1.1rem !important;
        }
        
        .fa-robot {
            font-size: 1.8em !important;
        }
    }
    
    @media (max-width: 360px) {
        .levels-grid-compact {
            grid-template-columns: repeat(5, 1fr) !important;
            gap: 4px !important;
        }
        
        .robot-level-btn-compact {
            padding: 8px 3px !important;
            min-height: 45px !important;
            font-size: 0.75rem !important;
        }
    }
    
    /* افکت‌های ساده */
    .robot-level-btn-compact:hover {
        transform: translateY(-2px) !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
    }
    
    #cancelRobotGame:hover {
        background: rgba(255,255,255,0.15) !important;
        border-color: rgba(255,255,255,0.3) !important;
    }
