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

html, body {
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
}

#app {
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.5vh, 12px);
  padding: clamp(4px, 1.5vh, 12px);
}

#title {
  font-size: clamp(1rem, 3vh, 1.6rem);
  font-weight: 700;
  letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(255, 165, 0, 0.3);
  flex-shrink: 0;
}

#main-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2vw, 20px);
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 800px;
}

/* ===== Side Panels ===== */
.side-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 1vh, 10px);
  padding: clamp(8px, 2vh, 20px);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  min-width: clamp(60px, 12vw, 100px);
  transition: background 0.3s, box-shadow 0.3s;
}

.widget.active-turn {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.15);
}

.widget-piece {
  width: clamp(32px, 6vh, 52px);
  height: clamp(32px, 6vh, 52px);
  border-radius: 50%;
  flex-shrink: 0;
}

.red-icon {
  background: radial-gradient(circle at 35% 35%, #ff6b6b, #c0392b);
  border: 3px solid #922b21;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.black-icon {
  background: radial-gradient(circle at 35% 35%, #636e72, #2d3436);
  border: 3px solid #1a1a1a;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.15);
}

.widget-name {
  font-size: clamp(0.85rem, 2vh, 1.2rem);
  font-weight: 600;
  letter-spacing: 1px;
}

.widget-score {
  font-size: clamp(1.5rem, 4vh, 2.8rem);
  font-weight: 700;
  line-height: 1;
}

.widget-dot {
  width: clamp(10px, 1.8vh, 16px);
  height: clamp(10px, 1.8vh, 16px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s;
  opacity: 0.3;
}

.widget-dot.active {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

#red-dot.active { background: #e74c3c; }
#black-dot.active { background: #2c3e50; }

/* ===== Board ===== */
#board-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

#board {
  width: min(70vmin, 100%);
  max-width: 520px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid #8B4513;
  border-radius: 6px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), 0 0 60px rgba(139, 69, 19, 0.2);
  overflow: hidden;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.cell.light { background: #f0d9b5; }
.cell.dark { background: #b58863; }

.cell.dark.valid-move { background: #7ec850; cursor: pointer; }
.cell.dark.valid-capture { background: #e74c3c; cursor: pointer; }
.cell.dark.selected { background: #f6e05e; }
.cell.dark.last-move { background: #cdd26a; }

.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
  z-index: 2;
}

.piece.red {
  background: radial-gradient(circle at 35% 35%, #ff6b6b, #c0392b);
  border: 3px solid #922b21;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.piece.black {
  background: radial-gradient(circle at 35% 35%, #636e72, #2d3436);
  border: 3px solid #1a1a1a;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.15);
}

.piece.king::after {
  content: '♛';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: min(3.5vw, 3.5vh, 22px);
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
  line-height: 1;
  pointer-events: none;
}

.piece:hover { transform: scale(1.05); }

.piece.selected {
  transform: scale(1.1);
  box-shadow: 0 0 20px rgba(246, 224, 94, 0.6), 0 3px 8px rgba(0, 0, 0, 0.4);
}

/* ===== Overlay ===== */
#overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  z-index: 10;
  backdrop-filter: blur(4px);
}

#overlay.hidden { display: none; }

#overlay-content {
  text-align: center;
  padding: clamp(16px, 4vh, 32px);
}

#overlay-content h2 {
  font-size: clamp(1.5rem, 5vh, 2.5rem);
  margin-bottom: clamp(8px, 2vh, 16px);
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
}

#play-again-btn,
#reset-btn {
  padding: clamp(6px, 1.2vh, 12px) clamp(16px, 3vw, 32px);
  font-size: clamp(0.75rem, 1.8vh, 1rem);
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: linear-gradient(135deg, #f39c12, #e67e22);
  color: #fff;
  transition: transform 0.2s, box-shadow 0.2s;
  letter-spacing: 1px;
}

#play-again-btn:hover,
#reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(243, 156, 18, 0.4);
}

#play-again-btn:active,
#reset-btn:active { transform: translateY(0); }

#reset-btn {
  flex-shrink: 0;
}

/* ===== Mobile / Small screens ===== */
@media (max-width: 520px) {
  #main-row {
    gap: 4px;
  }

  .widget {
    min-width: 50px;
    padding: 6px;
    gap: 3px;
  }

  .widget-piece {
    width: 28px;
    height: 28px;
  }

  .widget-score {
    font-size: 1.2rem;
  }

  .widget-name {
    font-size: 0.7rem;
  }
}
