* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #2d5016 0%, #1a2e0d 100%);
  color: #f5e6c8;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  width: 100%;
  max-width: 100%;
}

.hidden {
  display: none !important;
}

/* Top bar */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 90vmin;
  margin-bottom: 1rem;
}

.top-bar h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.actions button,
.mode-btn {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  border: 2px solid #c9a227;
  background: #4a7c23;
  color: #f5e6c8;
  border-radius: 6px;
  font-weight: 600;
}

.actions button:hover,
.mode-btn:hover {
  background: #5d9a2e;
}

.actions button:active,
.mode-btn:active {
  transform: scale(0.98);
}

/* Start screen */
#start-screen {
  text-align: center;
  padding: 2rem;
}

.start-title {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 280px;
  margin: 0 auto;
}

.mode-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

/* Game area */
#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.status {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  min-height: 1.5em;
}

/* Board - equal columns and rows */
.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  width: min(90vmin, 600px);
  height: min(90vmin, 600px);
  max-width: 100%;
  max-height: min(90vmin, 600px);
  border: 4px solid #5c3d1e;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.square {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: default;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.square.light {
  background: #e8d5b5;
}

.square.dark {
  background: #5c3d1e;
}

.square.dark.playable {
  cursor: pointer;
  background: #6d3535;
  box-shadow: inset 0 0 0 3px #d32f2f;
}

.square.dark.playable:hover {
  background: #8b4040;
  box-shadow: inset 0 0 0 4px #e53935;
}

.square.selected {
  box-shadow: inset 0 0 0 4px #e53935;
  background: #8b4040;
}

.square .piece {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.425rem, 6.8vmin, 3.4rem);  /* ~15% smaller */
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.square .piece .piece-icon {
  line-height: 1;
}

.square .piece.king {
  position: relative;
}

.square .piece.king .piece-crown {
  position: absolute;
  top: -0.08em;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.5em;
  line-height: 1;
  pointer-events: none;
}

.square.red .piece {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.square.black .piece {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.square.clickable .piece {
  pointer-events: auto;
  cursor: grab;
}

.square.clickable .piece:active {
  cursor: grabbing;
}

.square.clickable:hover .piece {
  transform: scale(1.05);
}

.square.dark.playable.drag-over {
  background: #9a4545;
  box-shadow: inset 0 0 0 4px #e53935;
}

/* Victory dance: bounce left twice, then right twice, repeat */
@keyframes piece-dance {
  0%, 100% { transform: translateX(0); }
  12% { transform: translateX(-10px); }
  25% { transform: translateX(0); }
  37% { transform: translateX(-10px); }
  50% { transform: translateX(0); }
  62% { transform: translateX(10px); }
  75% { transform: translateX(0); }
  87% { transform: translateX(10px); }
}

.square .piece.dance {
  animation: piece-dance 1.4s ease-in-out infinite;
}
