
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Color variables */
  --primary-green: #64a243;
  --dark-green: #4a7c59;
  --light-blue: #667eea;
  --purple: #764ba2;
  --wood-dark: #8B4513;
  --wood-light: #e8dcc6;
  --square-dark: #5a7a9b;
  --danger: #dc3545;
  --warning: #ffc107;
  --success: #4CAF50;
  
  /* Animation timings */
  --transition-fast: 0.2s;
  --transition-normal: 0.3s;
  --transition-slow: 0.5s;
  
  /* Z-index layers */
  --z-modal: 1000;
  --z-notification: 999;
  --z-controls: 10;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; /* More performant font stack */
  background: linear-gradient(135deg, var(--primary-green) 0%, var(--dark-green) 25%, var(--light-blue) 75%, var(--purple) 100%);
  background-size: 400% 400%;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  color: #333;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  animation: backgroundShift 20s ease-in-out infinite;
  /* Performance optimizations */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  will-change: auto;
  /* Mobile safe areas */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

@keyframes backgroundShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* Optimize animations for performance */
@media (prefers-reduced-motion: reduce) {
  body {
    animation: none;
  }
  
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Header Styles */
header {
  text-align: center;
  padding: clamp(15px, 3vw, 25px);
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

h1 {
  color: white;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  margin-bottom: 0.5em;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: clamp(1rem, 2.5vw, 1.2rem);
}

/* Player Zones - Consolidated common styles */
.player-zone {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 0 0 20px 20px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  backdrop-filter: blur(10px);
  overflow: hidden;
  transition: all var(--transition-normal) ease;
}

.top-player { 
  border-radius: 0 0 20px 20px;
  transform: rotate(180deg);
}

.bottom-player { 
  border-radius: 20px 20px 0 0; 
  margin-top: auto; 
}

/* Player Toggle */
.player-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  cursor: pointer;
  transition: background-color var(--transition-normal) ease;
  user-select: none;
}

.player-toggle:hover { background: rgba(255, 255, 255, 0.5); }

.player-label {
  font-size: 1.2em;
  color: #333;
  font-weight: bold;
}

.toggle-arrow {
  font-size: 1.2em;
  color: var(--primary-green);
  transition: transform var(--transition-normal) ease;
  font-weight: bold;
}

.toggle-arrow.rotated { transform: rotate(180deg); }

/* Player Controls */
.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  max-width: 100%;
  flex-wrap: wrap;
  padding: 0 15px 15px 15px;
  max-height: 200px;
  overflow: hidden;
  transition: all 0.4s ease;
  opacity: 1;
}

.player-controls.collapsed {
  max-height: 0;
  padding: 0 15px;
  opacity: 0;
}

.player-info {
  flex: 1;
}

.player-status {
  font-size: 0.9em;
  color: var(--primary-green);
  font-weight: bold;
  margin-top: 5px;
  padding: 4px 8px;
  background: rgba(100, 162, 67, 0.1);
  border-radius: 12px;
  text-align: center;
  transition: all var(--transition-normal) ease;
}

.player-status.active {
  background: rgba(100, 162, 67, 0.2);
  color: var(--dark-green);
  animation: statusPulse 2s ease-in-out infinite;
}

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

.color-control-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 150px;
}

.color-control-compact label {
  font-size: 0.9em;
  font-weight: bold;
  white-space: nowrap;
}

.color-picker-compact {
  width: 40px;
  height: 30px;
  border: 2px solid #ddd;
  border-radius: 5px;
  cursor: pointer;
  background: none;
  transition: border-color var(--transition-normal) ease;
}

.color-picker-compact:hover { border-color: #007bff; }

.reset-btn-compact {
  padding: 4px 8px;
  background: #6c757d;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.8em;
  cursor: pointer;
  transition: background var(--transition-normal) ease;
}

.reset-btn-compact:hover { background: #5a6268; }

.preset-colors-compact {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.preset-btn-compact {
  width: 35px;
  height: 35px;
  border: 2px solid #ddd;
  border-radius: 50%;
  font-size: 1.2em;
  cursor: pointer;
  transition: all var(--transition-normal) ease;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preset-btn-compact:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Game Area */
.game-area-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 15px;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  position: relative;
  gap: 10px;
}

/* Mirror effect: Only rotate the top player UI, not the board */
@media (min-height: 600px) {
  .top-player {
    transform: rotate(180deg);
  }
}

.game-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.9);
  padding: 10px 15px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  flex-shrink: 0;
  z-index: var(--z-controls);
}

.turn-indicator {
  font-weight: bold;
  font-size: 1em;
}

.turn-badge {
  font-weight: bold;
  padding: 5px 12px;
  border-radius: 8px;
  background: #e9ecef;
  display: inline-block;
  font-size: 0.9em;
  margin-left: 8px;
}

.turn-badge.white {
  background: linear-gradient(45deg, #f8f9fa, #e9ecef);
  color: #333;
}

.turn-badge.black {
  background: linear-gradient(45deg, #343a40, #495057);
  color: white;
}

.reset-btn-center, .control-btn {
  padding: 8px 12px;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  cursor: pointer;
  transition: all var(--transition-normal) ease;
  margin: 0 5px;
}

.reset-btn-center {
  background: linear-gradient(45deg, var(--danger), #c82333);
}

.reset-btn-center:hover {
  background: linear-gradient(45deg, #c82333, #a71e2a);
  transform: translateY(-1px);
}

.undo-btn {
  background: linear-gradient(45deg, #6c757d, #5a6268);
}

.undo-btn:hover:not(:disabled) {
  background: linear-gradient(45deg, #5a6268, #495057);
  transform: translateY(-1px);
}

.undo-btn:disabled {
  background: #e9ecef;
  color: #6c757d;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Player-specific undo buttons */
.player-undo-btn {
  padding: 6px 12px;
  background: linear-gradient(45deg, #6c757d, #5a6268);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85em;
  cursor: pointer;
  transition: all var(--transition-normal) ease;
  margin-left: 10px;
  min-width: 70px;
}

.player-undo-btn:hover:not(:disabled) {
  background: linear-gradient(45deg, #5a6268, #495057);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.player-undo-btn:disabled {
  background: #e9ecef;
  color: #6c757d;
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

/* Player Game Controls */
.player-game-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 10px 0;
  flex-wrap: wrap;
}

.player-game-controls .control-btn,
.player-game-controls .reset-btn-center {
  padding: 6px 12px;
  font-size: 0.9em;
  min-width: 100px;
}

/* Player Move History */
.player-move-history {
  margin: 10px 0;
}

.move-history-label {
  font-size: 0.9em;
  font-weight: bold;
  color: #555;
  margin-bottom: 5px;
  text-align: center;

.turn-indicator-container {
  display: flex;
  justify-content: center;
  margin: 10px 0;
  width: 100%;
}


}

.player-move-history .move-log-compact {
  height: 60px;
  font-size: 0.75em;
  margin: 0;
}

/* Chess Board - Optimized for performance */
.chess-board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 10px;
  box-sizing: border-box;
}

.chess-board {
  display: grid;
  grid-template-columns: 30px repeat(8, 1fr) 30px;
  grid-template-rows: 30px repeat(8, 1fr) 30px;
  width: min(85vw, 85vh, 450px); /* Use the smallest of viewport width, height, or max size */
  height: min(85vw, 85vh, 450px); /* Ensure square aspect ratio */
  max-width: 450px;
  max-height: 450px;
  border: 3px solid var(--wood-dark);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0,0,0,0.3);
  transition: transform var(--transition-slow) ease;
  flex-shrink: 0;
  /* GPU acceleration */
  transform: translateZ(0);
  will-change: transform;
}

.chess-board.flipped {
  transform: rotate(180deg);
}

.chess-board.flipped .square {
  transform: rotate(180deg);
}

/* Standard flip board behavior */
.chess-board.flipped {
  transform: rotate(180deg);
}

.chess-board.flipped .square {
  transform: rotate(180deg);
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2em;
  cursor: pointer;
  transition: all var(--transition-fast) ease;
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  aspect-ratio: 1; /* Ensure squares stay square */
  min-height: 0; /* Let flexbox handle sizing */
  min-width: 0; /* Let flexbox handle sizing */
  grid-column: auto;
  grid-row: auto;
}

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

.square:hover { 
  box-shadow: inset 0 0 15px rgba(255, 255, 0, 0.6); 
}

.square.selected {
  box-shadow: inset 0 0 15px rgba(100, 162, 67, 0.9), 0 0 20px rgba(100, 162, 67, 0.5);
  background-color: #8fbc8f !important;
  animation: selectedPulse 1.5s ease-in-out infinite;
}

@keyframes selectedPulse {
  0%, 100% { 
    box-shadow: inset 0 0 15px rgba(100, 162, 67, 0.9), 0 0 20px rgba(100, 162, 67, 0.5);
  }
  50% { 
    box-shadow: inset 0 0 25px rgba(100, 162, 67, 1), 0 0 30px rgba(100, 162, 67, 0.7);
  }
}

.square.valid-move {
  box-shadow: inset 0 0 15px rgba(255, 193, 7, 0.7);
  background-color: rgba(255, 193, 7, 0.3) !important;
  position: relative;
}

.square.valid-move::after {
  content: '●';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--warning);
  font-size: 1.5em;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
  animation: dotPulse 2s ease-in-out infinite;
}

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

.square.king-in-check {
  background-color: #ff6b6b !important;
  animation: checkPulse 1s infinite;
}

@keyframes checkPulse {
  0% { box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.8); }
  50% { box-shadow: inset 0 0 40px rgba(255, 0, 0, 1); }
  100% { box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.8); }
}

/* Coordinate labels on board edges */
.coordinate-file-label,
.coordinate-rank-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  user-select: none;
}

.coordinate-file-label {
  padding: 2px 0;
}

.coordinate-rank-label {
  padding: 0 2px;
}

.game-message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: rgba(248, 215, 218, 0.95);
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-radius: 20px;
  text-align: center;
  font-weight: bold;
  display: none;
  animation: messageSlide 0.3s ease;
  z-index: var(--z-notification);
  max-width: 90vw;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  backdrop-filter: blur(10px);
}

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

/* Enhanced Check Notification with Piece Images */
.check-notification {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  transform: scale(0.8);
  transition: all var(--transition-normal) ease;
}

.check-notification.show {
  opacity: 1;
  transform: scale(1);
}

.check-notification-content {
  background: linear-gradient(145deg, #ff4757, #ff6b7d);
  color: white;
  padding: 30px 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(255, 71, 87, 0.4);
  max-width: 90vw;
  animation: checkPulseNotification 1s ease-in-out infinite alternate;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.check-notification-content.for-black-player {
  transform: rotate(180deg);
}

@keyframes checkPulseNotification {
  0% { box-shadow: 0 20px 40px rgba(255, 71, 87, 0.4); }
  100% { box-shadow: 0 25px 50px rgba(255, 71, 87, 0.6); }
}

.check-piece-container {
  position: relative;
  width: 100px;
  height: 100px;
  margin-bottom: 15px;
}

.check-piece-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: checkPieceShake 0.5s ease-in-out infinite alternate;
}

.danger-overlay {
  position: absolute;
  top: -10px;
  right: -10px;
  font-size: 2em;
  animation: dangerPulse 1s ease-in-out infinite;
}

@keyframes checkPieceShake {
  0% { transform: rotate(-3deg); }
  100% { transform: rotate(3deg); }
}

@keyframes dangerPulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.3); opacity: 1; }
}

.check-text {
  font-size: 1.8em;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* Capture Notification */
.capture-notification {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-notification);
  opacity: 0;
  transform: translateX(-50%) scale(0.8);
  transition: all var(--transition-normal) ease;
}

.capture-notification.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.capture-notification-content {
  background: linear-gradient(145deg, #28a745, #34ce57);
  color: white;
  padding: 20px 30px;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 15px 30px rgba(40, 167, 69, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: captureBounce 0.6s ease-out;
}

@keyframes captureBounce {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.capture-piece-container {
  position: relative;
  width: 60px;
  height: 60px;
  margin-bottom: 10px;
}

.capture-piece-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: grayscale(50%);
  animation: captureRotate 0.8s ease-out;
}

.capture-overlay {
  position: absolute;
  top: -5px;
  right: -5px;
  font-size: 1.5em;
  animation: captureExplosion 0.6s ease-out;
}

@keyframes captureRotate {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(0.8); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes captureExplosion {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.5); opacity: 1; }
  100% { transform: scale(1); opacity: 0.8; }
}

.capture-text {
  font-size: 1.2em;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

/* Pawn Promotion Modal */
.promotion-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
}

.promotion-content {
  background: white;
  padding: 30px;
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  max-width: 90vw;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.promotion-content.for-black-player {
  transform: rotate(180deg);
}

.promotion-title {
  font-size: 1.5em;
  font-weight: bold;
  margin-bottom: 20px;
  color: #333;
}

.promotion-pieces {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.promotion-piece {
  width: 80px;
  height: 80px;
  border: 3px solid #ddd;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: #f8f9fa;
  transition: all var(--transition-normal) ease;
  font-size: 2.5em;
}

.promotion-piece:hover {
  border-color: #007bff;
  background: #e3f2fd;
  transform: scale(1.1);
  box-shadow: 0 5px 15px rgba(0,123,255,0.3);
}

.promotion-piece img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Game Over Modal */
.game-over-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1002;
}

.game-over-content {
  background: linear-gradient(145deg, var(--success), #45a049);
  color: white;
  padding: 40px;
  border-radius: 20px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(76, 175, 80, 0.4);
  max-width: 90vw;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.game-over-content.for-black-player {
  transform: rotate(180deg);
}

.game-over-title {
  font-size: 2.5em;
  font-weight: bold;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.game-over-message {
  font-size: 1.2em;
  margin-bottom: 30px;
}

.new-game-btn {
  padding: 15px 30px;
  background: white;
  color: var(--success);
  border: none;
  border-radius: 10px;
  font-size: 1.1em;
  font-weight: bold;
  cursor: pointer;
  transition: all var(--transition-normal) ease;
}

.new-game-btn:hover {
  background: #f0f0f0;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.piece {
  transition: all var(--transition-normal) ease;
  cursor: grab;
  user-select: none;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
  filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.3));
  /* Performance optimization */
  will-change: transform, filter;
}

.piece:hover {
  transform: scale(1.1);
  filter: drop-shadow(3px 3px 6px rgba(0,0,0,0.4)) brightness(1.1);
  animation: pieceGlow 1.5s ease-in-out infinite alternate;
}

@keyframes pieceGlow {
  0% { filter: drop-shadow(3px 3px 6px rgba(0,0,0,0.4)) brightness(1.1); }
  100% { filter: drop-shadow(3px 3px 8px rgba(100, 162, 67, 0.6)) brightness(1.2); }
}

.piece:active {
  cursor: grabbing;
}

.piece.white-custom {
  filter: hue-rotate(0deg) saturate(1) brightness(1);
  text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.piece.black-piece {
  transform: rotate(180deg);
}

.piece.black-custom {
  filter: hue-rotate(0deg) saturate(1) brightness(1);
  text-shadow: 1px 1px 2px rgba(255,255,255,0.3);
}

/* Move History */
.move-history-compact {
  width: 100%;
  max-width: 400px;
  height: 80px;
  flex-shrink: 0;
  z-index: var(--z-controls);
}

.move-log-compact {
  height: 100%;
  overflow-y: auto;
  padding: 8px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.8em;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  box-sizing: border-box;
  /* Scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: var(--primary-green) transparent;
}

.move-log-compact::-webkit-scrollbar {
  width: 6px;
}

.move-log-compact::-webkit-scrollbar-track {
  background: transparent;
}

.move-log-compact::-webkit-scrollbar-thumb {
  background-color: var(--primary-green);
  border-radius: 3px;
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .player-controls {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .player-controls h3 {
    text-align: center;
    min-width: auto;
  }

  .color-control-compact {
    justify-content: space-between;
    min-width: auto;
  }

  .preset-colors-compact {
    justify-content: center;
  }

  .chess-board {
    width: min(90vw, 75vh, 350px);
    height: min(90vw, 75vh, 350px);
    max-width: 350px;
    max-height: 350px;
  }

  .square {
    font-size: 1.8em;
    min-height: calc(min(90vw, 75vh, 350px) / 8);
  }

  .game-status {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }
}

@media (max-width: 380px) {
  .chess-board {
    width: min(88vw, 70vh, 320px);
    height: min(88vw, 70vh, 320px);
    max-width: 320px;
    max-height: 320px;
  }

  .square {
    font-size: 1.6em;
    min-height: calc(min(88vw, 70vh, 320px) / 8);
  }

  .player-zone {
    padding: 8px;
  }
}

/* Specific optimization for 9:16 mobile screens */
@media (max-width: 480px) and (min-aspect-ratio: 9/16) and (max-aspect-ratio: 10/16) {
  .chess-board {
    width: min(85vw, 65vh, 350px);
    height: min(85vw, 65vh, 350px);
  }
  
  .game-area-center {
    padding: 6px;
    gap: 6px;
  }
  
  .player-zone {
    padding: 6px;
  }
}

/* Landscape orientation - reduce vertical padding */
@media (orientation: landscape) and (max-height: 600px) {
  .player-zone {
    padding: 8px;
  }

  .game-area-center {
    padding: 8px;
  }

  .move-log-compact {
    max-height: 60px;
  }

  .chess-board {
    max-width: 350px;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .square.light { background-color: #ffffff; }
  .square.dark { background-color: #000000; }
  .square.selected { background-color: #ffff00 !important; }
}

/* Visual Learning Aids Styles */
.chess-board.visual-aids-enabled .square.attack-pattern {
  position: relative;
}

.chess-board.visual-aids-enabled .square.attack-pattern.move-indicator {
  background-color: rgba(76, 175, 80, 0.3) !important;
  box-shadow: inset 0 0 10px rgba(76, 175, 80, 0.6);
}

.chess-board.visual-aids-enabled .square.attack-pattern.move-indicator::after {
  content: '●';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #4CAF50;
  font-size: 1.5em;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
  animation: attackDotPulse 2s ease-in-out infinite;
}

.chess-board.visual-aids-enabled .square.attack-pattern.capture-indicator {
  background-color: rgba(255, 152, 0, 0.4) !important;
  box-shadow: inset 0 0 10px rgba(255, 152, 0, 0.8);
}

.chess-board.visual-aids-enabled .square.attack-pattern.capture-indicator::after {
  content: '⚔️';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2em;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
  animation: captureIndicatorPulse 1.5s ease-in-out infinite;
}

.chess-board.visual-aids-enabled .square.danger-zone {
  background-color: rgba(244, 67, 54, 0.3) !important;
  box-shadow: inset 0 0 15px rgba(244, 67, 54, 0.7);
  animation: dangerZonePulse 1s ease-in-out infinite alternate;
}

@keyframes attackDotPulse {
  0%, 100% { 
    opacity: 0.7; 
    transform: translate(-50%, -50%) scale(1); 
  }
  50% { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(1.3); 
  }
}

@keyframes captureIndicatorPulse {
  0%, 100% { 
    opacity: 0.8; 
    transform: translate(-50%, -50%) scale(1); 
  }
  50% { 
    opacity: 1; 
    transform: translate(-50%, -50%) scale(1.2); 
  }
}

@keyframes dangerZonePulse {
  0% { 
    box-shadow: inset 0 0 15px rgba(244, 67, 54, 0.7); 
  }
  100% { 
    box-shadow: inset 0 0 25px rgba(244, 67, 54, 1); 
  }
}

/* Print styles */
@media print {
  .player-controls,
  .game-message,
  .check-notification,
  .promotion-modal,
  .game-over-modal {
    display: none !important;
  }
  
  .chess-board {
    box-shadow: none;
    border: 2px solid #000;
  }
}
