* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
  color: #222;
  transition: background-color 0.3s, color 0.3s;
}

body.dark {
  background: #181c1f;
  color: #f0f0f0;
}

body.light-mode {
  background: #f0f0f0;
  color: #222;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

header h1 {
  margin: 0;
  color: inherit;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9em;
  color: inherit;
}

select {
  padding: 6px 10px;
  border: 1px solid #ccc;
  background: #fff;
  color: #222;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

body.dark select {
  background: #23272a;
  color: #f0f0f0;
  border-color: #444;
}

button {
  padding: 8px 12px;
  border: 1px solid #ccc;
  background: #fff;
  color: #222;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

button:hover {
  background: #eee;
}

body.dark button {
  background: #23272a;
  color: #f0f0f0;
  border-color: #444;
}

body.dark button:hover {
  background: #2c3135;
}

main {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 16px;
}

.board-container {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(40px, 1fr));
  grid-template-rows: repeat(8, minmax(40px, 1fr));
  width: min(90vw, 600px);
  aspect-ratio: 1;
  border: 6px solid #333;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 5vw, 36px);
  user-select: none;
}

.square.light {
  background: #f0d9b5;
}

.square.dark {
  background: #b58863;
}

.square.selected {
  outline: 3px solid #4caf50;
  outline-offset: -3px;
}

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

.piece {
  pointer-events: none;
}

/* Make white pieces more visible in dark mode with dark outline */
body.dark .square .piece {
  /* Add dark text stroke for better visibility */
  -webkit-text-stroke: 0.5px rgba(0, 0, 0, 0.8);
  text-stroke: 0.5px rgba(0, 0, 0, 0.8);
  /* Add multiple dark shadows to create outline effect */
  text-shadow: -1px -1px 0 rgba(0, 0, 0, 0.9), 1px -1px 0 rgba(0, 0, 0, 0.9),
    -1px 1px 0 rgba(0, 0, 0, 0.9), 1px 1px 0 rgba(0, 0, 0, 0.9),
    0 0 3px rgba(0, 0, 0, 0.8), 0 0 6px rgba(0, 0, 0, 0.6);
}

.side-panel {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

body.dark .side-panel {
  background: #23272a;
  border-color: #333;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.status {
  margin-bottom: 8px;
  font-weight: 600;
  color: inherit;
}

h3 {
  color: inherit;
}

#moveList {
  list-style: decimal inside;
  margin: 0;
  padding-left: 0;
  max-height: 70vh;
  overflow-y: auto;
  color: inherit;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
  }
  .board {
    width: 100%;
  }
}

