:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface2: #242433;
  --accent: #7c3aed;
  --accent-light: #a78bfa;
  --accent-glow: rgba(124, 58, 237, 0.4);
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --highlight: rgba(124, 58, 237, 0.5);
  --legal-dot: rgba(0, 0, 0, 0.25);
  --check: rgba(220, 38, 38, 0.7);
  --last-move: rgba(124, 58, 237, 0.3);
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --white-piece: #ffffff;
  --black-piece: #1a1a1a;
  --board-size: min(520px, 90vw);
  --sq: calc(var(--board-size) / 8);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 620px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

header {
  text-align: center;
  width: 100%;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-light), #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

#status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

#player-badge {
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#player-badge.host { background: var(--accent); color: white; }
#player-badge.guest { background: var(--surface2); color: var(--text-muted); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 16px;
  padding: 32px;
  width: min(400px, 90vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px var(--accent-glow);
}
.modal-box h2 { font-size: 1.5rem; margin-bottom: 8px; }
.modal-box p { color: var(--text-muted); margin-bottom: 20px; font-size: 0.9rem; }

.modal-box input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid #333;
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}
.modal-box input:focus { border-color: var(--accent); }

.modal-btns { display: flex; gap: 10px; }

button {
  flex: 1;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
button:hover { background: #6d28d9; transform: translateY(-1px); }
button.secondary { background: var(--surface2); color: var(--text-muted); }
button.secondary:hover { background: #2d2d40; color: var(--text); }

.error { color: #ef4444 !important; font-size: 0.85rem !important; margin-top: 8px !important; }
.hidden { display: none !important; }

/* Waiting screen */
#waiting-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  width: 100%;
}
.waiting-box {
  text-align: center;
  padding: 40px;
}
.waiting-box p { color: var(--text-muted); margin-top: 16px; }
.hint { font-size: 0.85rem !important; margin-top: 8px !important; }

.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Game area */
#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  width: var(--board-size);
  padding: 8px 4px;
  font-size: 0.9rem;
}
.player-info span { color: var(--text-muted); }
.player-info span:first-child { font-weight: 600; color: var(--text); font-size: 1rem; }

.color-badge {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  display: inline-block;
  flex-shrink: 0;
}
.color-badge.white { background: #fff; }
.color-badge.black { background: #1a1a1a; }

.captured-pieces { font-size: 1rem; letter-spacing: -2px; }

/* Board */
#board-container {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.coords { color: var(--text-muted); font-size: 0.7rem; font-weight: 600; }
.coords.vertical {
  display: flex; flex-direction: column;
  height: var(--board-size);
  justify-content: space-around;
  align-items: center;
  width: 16px;
}
.coords.horizontal {
  display: flex; flex-direction: row;
  width: var(--board-size);
  justify-content: space-around;
  margin-top: 4px;
}

#board {
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 2px var(--surface2);
  cursor: default;
  user-select: none;
}

.square {
  width: var(--sq);
  height: var(--sq);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: filter 0.1s;
}
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.selected { background: var(--highlight) !important; filter: brightness(1.15); }
.square.last-from, .square.last-to { background-blend-mode: multiply; filter: brightness(0.88); }
.square.last-from::after, .square.last-to::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--last-move);
  pointer-events: none;
}
.square.in-check { background: var(--check) !important; }
.square:hover { filter: brightness(1.08); }

.square.legal-move::before {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  background: var(--legal-dot);
  border-radius: 50%;
  z-index: 1;
  pointer-events: none;
}
.square.legal-capture::before {
  content: '';
  position: absolute;
  inset: 2px;
  border: 4px solid var(--legal-dot);
  border-radius: 50%;
  background: transparent;
  z-index: 1;
  pointer-events: none;
}

.piece {
  font-size: calc(var(--sq) * 0.72);
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  position: relative;
  transition: transform 0.1s;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
}
.piece:hover { transform: scale(1.08); }

/* Game message */
#game-message {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  width: var(--board-size);
}
#game-message.check { border-color: #ef4444; color: #ef4444; }
#game-message.info { border-color: var(--accent); color: var(--accent-light); }

/* Promotion */
#promotion-choices {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}
.promo-piece {
  font-size: 2.5rem;
  cursor: pointer;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface2);
  transition: all 0.2s;
  flex: none;
}
.promo-piece:hover { background: var(--accent); transform: scale(1.1); }

/* Game over */
#game-over-screen {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(6px);
}
.game-over-box {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 60px var(--accent-glow);
  max-width: 360px;
  width: 90vw;
}
.game-over-box h2 { font-size: 2rem; margin-bottom: 12px; }
.game-over-box p { color: var(--text-muted); margin-bottom: 24px; }
.game-over-box button { width: 100%; }

@media (max-width: 480px) {
  header h1 { font-size: 1.5rem; }
}
