:root {
  --bg: #0f0f1a;
  --bg-gradient: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #0f0f1a 100%);
  --board-light: #e8d5b7;
  --board-dark: #b58863;
  --board-light-hover: #f0ddb8;
  --board-dark-hover: #c4946d;
  --text: #ffffff;
  --text-muted: rgba(255,255,255,0.6);
  --accent: #4a9eff;
  --accent-glow: rgba(74, 158, 255, 0.3);
  --highlight: rgba(74, 158, 255, 0.4);
  --capture: rgba(255, 74, 74, 0.3);
  --shadow: rgba(0, 0, 0, 0.5);
  --frame-wood: #5c3a1e;
  --frame-light: #8b5e3c;
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  padding: 10px;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 20px;
}

/* ===== HEADER / PLAYER INFO ===== */
header {
  padding: 8px 0;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;  background: rgba(255,255,255,0.05);
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 10px;
}

.bottom-header {
  margin-top: 10px;
  margin-bottom: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.player-details {
  flex: 1;
  min-width: 0;
}

.player-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
}

.player-status {
  font-size: 12px;
  color: var(--text-muted);
}

.player-info.active .player-status {
  color: var(--accent);
  font-weight: 600;
}

.timer {
  font-size: 16px;
  font-weight: 700;
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: rgba(255,255,255,0.1);
  padding: 6px 10px;  border-radius: 8px;
  min-width: 60px;
  text-align: center;
}

.timer.low {
  color: #ff4a4a;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== 3D BOARD ===== */
.board-wrapper {
  perspective: 1200px;
  padding: 10px 0;
}

.board-3d {
  transform: rotateX(8deg);
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.board-frame {
  background: linear-gradient(145deg, var(--frame-light), var(--frame-wood));
  padding: 8px;
  border-radius: 12px;
  box-shadow: 
    0 20px 60px var(--shadow),
    0 4px 12px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.15);
  position: relative;
  overflow: hidden;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.board-shine {
  position: absolute;  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 50%);
  pointer-events: none;
  border-radius: 12px;
}

.board-shadow {
  height: 30px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.4) 0%, transparent 70%);
  margin-top: -10px;
  transform: translateY(10px);
}

.square {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  font-size: 0;
}

.square svg {
  width: 80%;
  height: 80%;
  filter: drop-shadow(1px 2px 2px rgba(0,0,0,0.3));
  transition: transform 0.2s ease;
}

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

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

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

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

.square.selected {
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 2;}

.square.highlight::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0.6;
  pointer-events: none;
}

.square.capture-highlight::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  opacity: 0.6;
  pointer-events: none;
}

.square.last-move {
  background: rgba(74, 158, 255, 0.25) !important;
}

.square.check {
  background: radial-gradient(circle, rgba(255,0,0,0.6) 0%, rgba(255,0,0,0.2) 70%) !important;
}

/* ===== COORDINATES ===== */
.coord-file, .coord-rank {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
}

.coord-file {
  bottom: 2px;
  right: 4px;
}

.coord-rank {
  top: 2px;
  left: 4px;
}

.square.light .coord-file,.square.light .coord-rank {
  color: var(--board-dark);
}

.square.dark .coord-file,
.square.dark .coord-rank {
  color: var(--board-light);
}

/* ===== GAME INFO ===== */
.game-info {
  margin-top: 12px;
}

.move-history {
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.08);
}

.history-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 60px;
  overflow-y: auto;
  font-size: 13px;
  font-family: 'SF Mono', monospace;
}

.history-list span {
  background: rgba(255,255,255,0.08);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-muted);
}

.history-list span:nth-child(odd) {
  color: var(--text);
}

/* ===== CONTROLS ===== */.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

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

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:active {
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
}

.btn-secondary:active {
  background: rgba(255,255,255,0.15);
}

/* ===== RESULT MODAL ===== */
.result-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}

.result-content {
  background: linear-gradient(145deg, #1e1e32, #15152a);
  padding: 32px 24px;
  border-radius: 24px;
  text-align: center;
  max-width: 300px;
  width: 90%;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: slideUp 0.4s ease;
}

.result-icon {
  font-size: 56px;
  margin-bottom: 12px;
}

.result-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 8px;
}

.result-message {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.result-modal .btn {
  width: 100%;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ===== ANIMATIONS ===== */
.square svg.piece-enter {  animation: pieceAppear 0.3s ease;
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 380px) {
  .square svg {
    width: 75%;
    height: 75%;
  }
  .player-info {
    padding: 8px 10px;
  }
  .avatar {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  .timer {
    font-size: 14px;
    padding: 4px 8px;
  }
}

@media (max-height: 700px) {
  .board-3d {
    transform: rotateX(4deg);
  }
  .game-info {
    display: none;
  }
}
