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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.game-container {
  text-align: center;
}

h1 {
  color: #e8d5b7;
  font-size: 2.2rem;
  margin-bottom: 15px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.main-area {
  display: flex;
  gap: 25px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

.board-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-wrapper {
  display: flex;
  align-items: stretch;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(80vw, 480px);
  height: min(80vw, 480px);
  border: 4px solid #8b7355;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  overflow: hidden;
  touch-action: none;
}

.square {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: min(8vw, 48px);
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s;
  user-select: none;
}

.square.light { background-color: #f0d9b5; }
.square.dark { background-color: #b58863; }
.square.selected { background-color: #7fc97f !important; }

.square.legal-move::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 50%;
}

.square.legal-capture {
  background-color: #ff6b6b !important;
}
.square.legal-capture::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border: 5px solid rgba(255, 107, 107, 0.7);
  border-radius: 50%;
  box-sizing: border-box;
}

.square.last-move { background-color: #cdd26a !important; }

.square.check {
  background: radial-gradient(circle, #ff0000 0%, #ff6b6b 50%, transparent 70%) !important;
}

.piece {
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  line-height: 1;
}

/* Coordinates */
.coords {
  display: flex;
  color: #8b7355;
  font-size: 13px;
  font-weight: bold;
}
.coords-left, .coords-right {
  flex-direction: column;
  width: 22px;
}
.coords-left span, .coords-right span {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.coords-bottom {
  flex-direction: row;
  height: 22px;
}
.coords-bottom span {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Player info */
.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  margin: 8px 0;
  color: #fff;
  min-width: 300px;
  transition: all 0.3s;
}
.player-info.active {
  background: rgba(255,255,255,0.22);
  box-shadow: 0 0 15px rgba(255,255,255,0.15);
}
.player-icon { font-size: 1.8rem; }
.player-name { font-weight: bold; font-size: 1rem; }

.timer {
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: bold;
  margin-left: auto;
  padding: 4px 12px;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
  min-width: 60px;
}
.timer.low {
  color: #ff4444;
  animation: timerPulse 1s infinite;
}
@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.captured {
  font-size: 1.3rem;
  letter-spacing: 1px;
  margin-left: 8px;
}

/* Side panel */
.side-panel {
  background: rgba(255,255,255,0.08);
  border-radius: 15px;
  padding: 18px;
  min-width: 240px;
  color: #fff;
}

.score-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 10px;
  color: #e8d5b7;
}
.score-dash { color: #8b7355; }

.status {
  font-size: 1.1rem;
  font-weight: bold;
  padding: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  margin-bottom: 12px;
}
.status.check {
  color: #ff6b6b;
  animation: pulse 1s infinite;
}
.status.mate {
  color: #ffd700;
  font-size: 1.2rem;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.move-list-container h3 {
  margin-bottom: 8px;
  color: #e8d5b7;
  font-size: 0.95rem;
}
.move-list {
  max-height: 250px;
  overflow-y: auto;
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 12px;
}
.move-list::-webkit-scrollbar { width: 5px; }
.move-list::-webkit-scrollbar-thumb { background: #8b7355; border-radius: 3px; }

.move-entry {
  display: flex;
  gap: 8px;
  padding: 3px 5px;
  font-family: monospace;
  font-size: 13px;
}
.move-number { color: #8b7355; min-width: 28px; }
.move-white, .move-black { min-width: 55px; }
.move-entry:nth-child(odd) { background: rgba(255,255,255,0.03); }

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

button {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
#newGameBtn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}
#flipBtn, #undoBtn {
  background: rgba(255,255,255,0.15);
  color: white;
}
.btn-resign {
  background: rgba(255,80,80,0.3) !important;
  color: #ff8888 !important;
}
button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
button:active { transform: translateY(0); }

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.85);
  justify-content: center;
  align-items: center;
  z-index: 100;
}
.modal.active { display: flex; }

.modal-content {
  background: linear-gradient(135deg, #2a2a4a, #1a1a3a);
  padding: 30px;
  border-radius: 18px;
  text-align: center;
  max-width: 450px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}
.modal-content h3 {
  color: #e8d5b7;
  margin-bottom: 20px;
  font-size: 1.4rem;
}

.modal-section {
  margin-bottom: 18px;
  text-align: left;
}
.modal-section label {
  display: block;
  color: #aaa;
  font-size: 0.85rem;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-option {
  padding: 8px 14px;
  background: rgba(255,255,255,0.08);
  color: #ccc;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn-option:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.btn-option.active {
  background: rgba(102, 126, 234, 0.3);
  border-color: #667eea;
  color: #fff;
}

.btn-start {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 14px 40px;
  font-size: 1.1rem;
  margin-top: 10px;
}

/* Promotion */
.promotion-choices {
  display: flex;
  gap: 15px;
  justify-content: center;
}
.promotion-piece {
  font-size: 55px;
  padding: 12px 18px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.promotion-piece:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.15);
}

/* Drag ghost */
.drag-ghost {
  position: fixed;
  font-size: 52px;
  pointer-events: none;
  z-index: 9999;
  text-shadow: 0 4px 12px rgba(0,0,0,0.5);
  opacity: 0.9;
  transform: translate(-50%, -50%);
}

@media (max-width: 768px) {
  h1 { font-size: 1.6rem; margin-bottom: 10px; }
  .main-area { flex-direction: column; align-items: center; }
  .player-info { min-width: unset; width: 100%; max-width: 400px; }
  .side-panel { width: 100%; max-width: 400px; }
  .timer { font-size: 1.1rem; }
}
