:root {
  --bg-color: #0f111a;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --board-light: #eeeed2;
  --board-dark: #769656;
  --highlight-blue: rgba(59, 130, 246, 0.6);
  --move-hint: rgba(59, 130, 246, 0.8);
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.1);
  --danger: #ef4444;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at center, #1e293b 0%, #0f111a 100%);
}

#app {
  width: 100%;
  max-width: 1200px;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s ease forwards;
  width: 100%;
  padding: 2rem;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  max-width: 400px;
}

.screen.active {
  display: flex;
}

.overlay-screen {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  background: rgba(15, 17, 26, 0.95);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 3rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), 0 0 50px var(--accent-hover);
  text-align: center;
}

.overlay-screen.active {
  display: flex;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

#winner-text {
  font-size: 3.5rem;
  margin-bottom: 2rem;
  background: linear-gradient(135deg, #fcd34d, #f59e0b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

h1 {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #c084fc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
  text-align: center;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 3rem;
  text-align: center;
}

h2 {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 2rem;
  color: var(--text-main);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.btn {
  font-family: 'Outfit', sans-serif;
  padding: 1rem 2rem;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  text-align: center;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

.btn:active {
  transform: translateY(0);
}

.primary {
  background: var(--accent);
  color: white;
}

.primary:hover {
  background: var(--accent-hover);
}

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

.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.text {
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
}

.text:hover {
  color: white;
  box-shadow: none;
}

/* Range Slider */
.level-selector {
  width: 100%;
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#level-value {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 1rem;
  color: var(--accent);
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: transparent;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 24px;
  width: 24px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  margin-top: -10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

/* Game Interface */
#game-screen {
  max-width: 100%;
  padding: 1.5rem;
  background: transparent;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
}

.game-layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 2rem;
  width: 100%;
}

.game-sidebar {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 1.5rem;
  padding: 1rem 1.5rem;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
}

.turn-indicator {
  font-size: 1.2rem;
  font-weight: 600;
}

.turn-indicator.white {
  color: #f8fafc;
}

.turn-indicator.black {
  color: #94a3b8;
}

.small.text {
  width: auto;
  padding: 0.5rem 1rem;
}

/* Chessboard */
#chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(85vw, 650px);
  height: min(85vw, 650px);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  border: 2px solid var(--glass-border);
  position: relative;
  transition: transform 0.5s ease;
}

#chessboard.rotated {
  transform: rotate(180deg);
}

.square {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

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

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

.square.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  background-color: var(--highlight-blue);
  mix-blend-mode: multiply;
}

/* Move hint styling - The blue shade the user requested */
.square.move-hint::before {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background-color: var(--move-hint);
  z-index: 10;
  pointer-events: none;
}

.square.move-hint.has-piece::before {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background-color: transparent;
  border: 4px solid var(--move-hint);
  box-sizing: border-box;
}

/* Pieces */
.piece {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  background-size: 80%;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 20;
  transition: left 0.3s ease, top 0.3s ease, transform 0.5s ease, filter 0.2s ease, opacity 0.3s ease;
  pointer-events: none;
  /* Let the square handle the clicks */
}

/* If board is rotated, pieces must be counter-rotated */
#chessboard.rotated .piece {
  transform: rotate(180deg);
}

/* Piece dragging/hover effect */
.piece.selected {
  transform: scale(1.15) translateY(-5px);
  filter: drop-shadow(0 10px 8px rgba(0, 0, 0, 0.5));
}

#chessboard.rotated .piece.selected {
  transform: rotate(180deg) scale(1.15) translateY(5px);
}

/* Captured pieces styling */
.captured-box {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 5px;
  margin-top: 10px;
  min-height: 50px;
  width: 100%;
}

.captured-box img {
  width: 30px;
  height: 30px;
}

.score-container {
  font-size: 1.2rem;
  font-weight: bold;
  margin-top: 10px;
  color: var(--text-main);
}


#game-status {
  margin-top: 1.5rem;
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  color: var(--danger);
  min-height: 1.5rem;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.8);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 900px) {
  .game-layout {
    flex-direction: column;
    align-items: center;
  }

  .game-sidebar {
    width: 100%;
    max-width: 400px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    padding: 1rem;
  }

  .game-sidebar h3 {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
    justify-self: start;
  }

  .score-container {
    grid-column: 2;
    grid-row: 1;
    margin: 0;
    justify-self: center;
  }

  .undo-btn {
    grid-column: 3;
    grid-row: 1;
    margin: 0 !important;
    justify-self: end;
  }

  .captured-box {
    grid-column: 1 / -1;
    grid-row: 2;
    margin-top: 10px;
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 2.5rem;
  }

  .screen {
    padding: 1rem;
    border-radius: 0;
    min-height: 100vh;
    justify-content: flex-start;
  }

  #main-menu,
  #cpu-selection {
    justify-content: center;
  }

  .game-layout {
    gap: 0.5rem;
  }

  .game-sidebar {
    padding: 0.5rem 1rem;
    max-width: 100%;
    margin: 0;
  }

  .game-sidebar h3 {
    font-size: 1.2rem;
  }

  .score-container {
    font-size: 1rem;
  }

  .undo-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  .game-header {
    margin-bottom: 0.5rem;
    padding: 0.5rem 1rem;
  }

  #chessboard {
    width: min(95vw, 650px);
    height: min(95vw, 650px);
  }

  .captured-box {
    margin-top: 5px;
    min-height: 25px;
    width: auto;
  }

  .captured-box img {
    width: 20px;
    height: 20px;
  }
}