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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#app {
  width: 100%;
  max-width: 500px;
  padding: 16px;
}

.hidden { display: none !important; }

/* Lobby */
#lobby {
  text-align: center;
}

#lobby h1 {
  font-size: 2rem;
  margin-bottom: 32px;
  color: #e2b04a;
}

.lobby-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.lobby-buttons button, .join-group button {
  background: #e2b04a;
  color: #1a1a2e;
  border: none;
  padding: 14px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.lobby-buttons button:hover, .join-group button:hover {
  background: #f0c66e;
}

.divider {
  color: #888;
  font-size: 0.9rem;
}

.join-group {
  display: flex;
  gap: 8px;
}

#input-code {
  background: #16213e;
  border: 2px solid #333;
  color: #eee;
  padding: 12px 16px;
  font-size: 1.2rem;
  border-radius: 8px;
  width: 160px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 3px;
}

#input-code:focus {
  outline: none;
  border-color: #e2b04a;
}

.error {
  color: #ff6b6b;
  margin-top: 12px;
}

/* Waiting */
#waiting {
  text-align: center;
}

#waiting h2 {
  margin-bottom: 24px;
  color: #e2b04a;
}

.code-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}

#game-code {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 8px;
  color: #e2b04a;
  font-family: 'Courier New', monospace;
}

#btn-copy {
  background: #333;
  color: #eee;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

#btn-copy:hover { background: #444; }

#qr-code {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

#qr-code canvas {
  border-radius: 8px;
}

#waiting p {
  color: #888;
  font-size: 0.9rem;
}

/* Game */
#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 8px 12px;
  background: #16213e;
  border-radius: 8px;
}

#status-text {
  font-weight: 600;
}

#game-id-display {
  font-size: 0.8rem;
  color: #888;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  min-height: 36px;
}

.player-label {
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 60px;
}

.captured {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  font-size: 1.1rem;
}

#board-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  margin: 4px 0;
}

#board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(6vw, 3rem);
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}

.square.light { background: #f0d9b5; }
.square.dark { background: #b58863; }
.square.selected { background: #7fc97f !important; }
.square.legal-move::after {
  content: '';
  width: 30%;
  height: 30%;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  position: absolute;
}
.square.legal-capture::after {
  content: '';
  width: 85%;
  height: 85%;
  border: 4px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  position: absolute;
  box-sizing: border-box;
}
.square.last-move { background: rgba(255, 255, 100, 0.4) !important; }
.square.check { background: #ff4444 !important; }

.piece {
  pointer-events: none;
  line-height: 1;
}

/* Promotion */
#promotion-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.promotion-pieces {
  display: flex;
  gap: 8px;
  background: #1a1a2e;
  padding: 16px;
  border-radius: 12px;
}

.promotion-piece {
  font-size: 2.5rem;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0d9b5;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s;
}

.promotion-piece:hover {
  transform: scale(1.15);
}

/* Game buttons */
#game-buttons {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

#btn-resign {
  background: #c0392b;
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}

#btn-resign:hover { background: #e74c3c; }

/* Game Over */
#gameover-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.gameover-box {
  background: #16213e;
  padding: 32px;
  border-radius: 16px;
  text-align: center;
  max-width: 320px;
}

.gameover-box h2 {
  font-size: 1.5rem;
  color: #e2b04a;
  margin-bottom: 8px;
}

.gameover-box p {
  margin-bottom: 20px;
  color: #aaa;
}

#btn-newgame {
  background: #e2b04a;
  color: #1a1a2e;
  border: none;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}

#btn-newgame:hover { background: #f0c66e; }

/* Mobile adjustments */
@media (max-width: 500px) {
  #app { padding: 8px; }
  .square { font-size: 10vw; }
  #game-code { font-size: 2rem; letter-spacing: 6px; }
}
