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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-light: #1f2b4d;
  --text: #eaeaea;
  --text-muted: #a0a0b0;
  --accent: #e94560;
  --light-square: #f0d9b5;
  --dark-square: #b58863;
  --highlight-selected: rgba(20, 85, 30, 0.55);
  --highlight-move: rgba(20, 85, 30, 0.35);
  --highlight-capture: rgba(180, 40, 40, 0.45);
  --highlight-last: rgba(155, 199, 0, 0.45);
  --highlight-check: rgba(220, 50, 50, 0.65);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --piece-white: #f5f5f5;
  --piece-white-stroke: #222222;
  --piece-black: #111111;
  --piece-black-stroke: #f0f0f0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.game-area {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.board-wrapper {
  flex-shrink: 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(72vw, 560px);
  height: min(72vw, 560px);
  border: 4px solid #333;
  border-radius: 4px;
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  font-size: clamp(2rem, 8vw, 3.5rem);
  line-height: 1;
  transition: background-color 0.1s;
}

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

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

.square.selected {
  background-color: var(--highlight-selected) !important;
}

.square.legal-move::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.square.legal-capture::after {
  content: '';
  position: absolute;
  width: 88%;
  height: 88%;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.25);
  background: transparent;
  pointer-events: none;
}

.square.last-move {
  background-color: var(--highlight-last) !important;
}

.square.in-check {
  background-color: var(--highlight-check) !important;
}

.piece {
  pointer-events: none;
  z-index: 1;
  font-weight: 700;
}

.piece.piece-white {
  color: var(--piece-white);
  -webkit-text-stroke: 1.5px var(--piece-white-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.piece.piece-black {
  color: var(--piece-black);
  -webkit-text-stroke: 1.5px var(--piece-black-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.25));
}

.sidebar {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.status-card,
.move-history-card,
.settings-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.status-card h2,
.move-history-card h2,
.settings-card h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.status-text {
  font-size: 1.15rem;
  font-weight: 600;
}

.status-text.check {
  color: #ff6b6b;
}

.status-text.game-over {
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field select {
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-light);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
}

.field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.board.thinking {
  opacity: 0.85;
  pointer-events: none;
}

.controls {
  display: flex;
  gap: 0.5rem;
}

.btn {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  transform: scale(0.98);
}

.move-list {
  list-style: decimal;
  padding-left: 1.25rem;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.move-list li {
  padding: 0.15rem 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
  z-index: 1;
}

.modal-content h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.promotion-options {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.promotion-btn {
  font-size: 2.5rem;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-light);
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.promotion-btn:hover {
  border-color: var(--accent);
  background: var(--bg);
}

.promotion-btn.piece-white {
  color: var(--piece-white);
  -webkit-text-stroke: 1.5px var(--piece-white-stroke);
  paint-order: stroke fill;
}

.promotion-btn.piece-black {
  color: var(--piece-black);
  -webkit-text-stroke: 1.5px var(--piece-black-stroke);
  paint-order: stroke fill;
}

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

  .sidebar {
    width: 100%;
    max-width: min(72vw, 560px);
  }
}
