:root {
  --bg-color: #070a12;
  --card-bg: #111827;
  --card-border: #1f293d;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-gold: #fbbf24;
  --accent-cyan: #38bdf8;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  
  --sq-light: #eedbc2;
  --sq-dark: #b88753;
  --sq-selected: rgba(245, 158, 11, 0.7);
  --sq-last-move: rgba(254, 240, 138, 0.4);
  --sq-hint: rgba(56, 189, 248, 0.85);
  --sq-check: rgba(239, 68, 68, 0.85);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Vazirmatn", -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 0% 0%, rgba(30, 27, 75, 0.4) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(15, 23, 42, 0.6) 0px, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px 10px;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Big Prominent Match Banner */
.special-match-banner {
  background: linear-gradient(135deg, #1e1b4b, #1e293b, #0f172a);
  border: 2px solid #4338ca;
  border-radius: 18px;
  padding: 16px 14px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(67, 56, 202, 0.35), inset 0 0 20px rgba(99, 102, 241, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.special-match-banner::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

.banner-badge {
  background: linear-gradient(135deg, #b45309, #d97706);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 3px 12px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.4);
}

.match-title {
  font-size: 1.18rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  line-height: 1.5;
}

.p-name.p1 {
  color: #fef08a;
  text-shadow: 0 0 12px rgba(254, 240, 138, 0.5);
}

.swords-icon {
  font-size: 1.1rem;
  animation: pulse-swords 2s infinite ease-in-out;
}

@keyframes pulse-swords {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2) rotate(10deg); }
}

.p-name.p2 {
  color: #60a5fa;
  text-shadow: 0 0 12px rgba(96, 165, 250, 0.5);
}

.match-subtitle {
  font-size: 0.78rem;
  color: #cbd5e1;
  opacity: 0.85;
}

/* Header & Connection status */
.game-header {
  display: flex;
  justify-content: center;
  align-items: center;
}

.room-status {
  font-size: 0.78rem;
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.1);
  padding: 3px 10px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.2);
}

/* Players Info Bar */
.players-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.player-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-badge {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid #64748b;
  flex-shrink: 0;
}

.white-badge { 
  background: #ffffff; 
  border-color: #f8fafc;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.black-badge { 
  background: #0f172a; 
  border-color: #475569;
  box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.2);
}

.player-info {
  display: flex;
  flex-direction: column;
}

.player-title {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.player-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: #fff;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.status-dot.online { 
  background: var(--accent-green); 
  box-shadow: 0 0 10px var(--accent-green); 
}

.status-dot.offline { 
  background: #475569; 
}

.vs-badge {
  font-weight: 900;
  font-size: 0.85rem;
  color: #64748b;
  letter-spacing: 1px;
}

/* Turn Indicator */
.turn-indicator {
  background: #1e293b;
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  font-size: 0.94rem;
  font-weight: 700;
  transition: all 0.25s ease;
}

.turn-indicator.my-turn {
  background: linear-gradient(135deg, #064e3b, #047857);
  border-color: #10b981;
  color: #ffffff;
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.4);
}

.turn-indicator.enemy-turn {
  background: #131d2e;
  color: var(--text-secondary);
}

/* Chessboard Area (مرتب، منظم و فیکس) */
.board-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 4px 0;
}

.chessboard {
  width: min(92vw, 470px);
  height: min(92vw, 470px);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 5px solid #283548;
  border-radius: 12px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.05);
  user-select: none;
  overflow: hidden;
  touch-action: manipulation;
  aspect-ratio: 1 / 1;
}

.square {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.12s ease;
  width: 100%;
  height: 100%;
}

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

.square.selected {
  background-color: var(--sq-selected) !important;
  box-shadow: inset 0 0 14px rgba(245, 158, 11, 0.95);
}

.square.last-move {
  background-color: var(--sq-last-move) !important;
}

.square.check {
  background-color: var(--sq-check) !important;
  animation: pulse-check 1.2s infinite alternate;
}

.square.ai-hint-from,
.square.ai-hint-to {
  box-shadow: inset 0 0 0 4px var(--accent-cyan), 0 0 18px var(--accent-cyan) !important;
  background-color: rgba(6, 182, 212, 0.45) !important;
  z-index: 4;
}

@keyframes pulse-check {
  from { box-shadow: inset 0 0 8px rgba(239, 68, 68, 0.6); }
  to { box-shadow: inset 0 0 25px rgba(239, 68, 68, 1); }
}

/* Valid Move Dot */
.move-dot {
  width: 30%;
  height: 30%;
  background-color: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  pointer-events: none;
  z-index: 3;
}

.square.has-piece .move-dot {
  width: 86%;
  height: 86%;
  background-color: transparent;
  border: 4px solid rgba(0, 0, 0, 0.45);
  border-radius: 50%;
}

/* Chess Piece Image */
.piece {
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
  z-index: 2;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.4));
  transition: transform 0.15s ease-out;
}

/* Coordinates labels */
.coord-rank, .coord-file {
  position: absolute;
  font-size: 0.66rem;
  font-weight: 800;
  pointer-events: none;
  opacity: 0.7;
  color: #1e293b;
}

.square.dark .coord-rank, .square.dark .coord-file { color: #f8fafc; }
.coord-rank { top: 2px; right: 3px; }
.coord-file { bottom: 1px; left: 3px; }

/* SECRET VIP AI PANEL (Amir Only) */
.secret-ai-card {
  background: linear-gradient(135deg, #1e1b4b, #0f172a);
  border: 2px solid #6366f1;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: glow-border 2.5s infinite alternate;
}

@keyframes glow-border {
  from { border-color: #6366f1; box-shadow: 0 0 15px rgba(99, 102, 241, 0.25); }
  to { border-color: #a855f7; box-shadow: 0 0 30px rgba(168, 85, 247, 0.5); }
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-title {
  font-size: 0.92rem;
  font-weight: 800;
  color: #e0e7ff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-badge {
  background: #4f46e5;
  color: #fff;
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 700;
}

.ai-hint-box {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.86rem;
  color: #38bdf8;
  text-align: center;
  font-weight: 600;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn:active { transform: scale(0.97); }

.btn-ai-hint {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #fff;
}

.btn-ai-play {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
}

.auto-ai-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #cbd5e1;
  cursor: pointer;
  margin-top: 2px;
}

.auto-ai-toggle input {
  cursor: pointer;
  accent-color: #8b5cf6;
  width: 17px;
  height: 17px;
}

/* History Card */
.history-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-card h3 {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.moves-count {
  font-size: 0.74rem;
  color: #64748b;
}

.history-list {
  max-height: 75px;
  overflow-y: auto;
  font-size: 0.82rem;
  line-height: 1.6;
  color: #e2e8f0;
}

.history-empty {
  color: #64748b;
  font-size: 0.78rem;
}

/* Reset Button */
.btn-secondary {
  background: #1e293b;
  border: 1px solid var(--card-border);
  color: #cbd5e1;
  width: 100%;
}

.btn-secondary:hover { background: #334155; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}

.modal-box {
  background: #1e293b;
  border: 2px solid #4338ca;
  border-radius: 20px;
  padding: 26px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.modal-trophy {
  font-size: 2.5rem;
}

.modal-box h2 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
}

.modal-box p {
  font-size: 0.95rem;
  color: #cbd5e1;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  width: 100%;
  margin-top: 6px;
}
