:root {
  color-scheme: dark;
  --bg: #17120e;
  --panel: #241a14;
  --panel-soft: #30241c;
  --text: #fff7ec;
  --muted: #d6bfa7;
  --accent: #f5b047;
  --accent-2: #8bd17c;
  --dark-cell: #7a4b2a;
  --light-cell: #e7c79e;
  --danger: #f36f5a;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(245, 176, 71, 0.18), transparent 32rem),
    linear-gradient(135deg, #120d0a, var(--bg));
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app {
  width: 100%;
  max-width: 980px;
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 24px;
  padding: clamp(18px, 4vw, 40px);
}

.hero {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 5rem);
  line-height: 0.95;
}

.subtitle {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2.2vw, 1.18rem);
}

.game-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  padding: clamp(14px, 3vw, 24px);
  border: 1px solid rgba(255, 247, 236, 0.12);
  border-radius: 28px;
  background: rgba(36, 26, 20, 0.86);
  box-shadow: 0 24px 60px var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: center;
}

.topbar > div,
.topbar button {
  min-height: 60px;
  border: 1px solid rgba(255, 247, 236, 0.12);
  border-radius: 18px;
  background: var(--panel-soft);
}

.topbar > div {
  display: grid;
  gap: 4px;
  padding: 10px 14px;
}

.label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar strong {
  font-size: 1.08rem;
}

.topbar button {
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.topbar button:hover,
.topbar button:focus-visible {
  border-color: var(--accent);
  background: #3d2c20;
  transform: translateY(-1px);
}

.message {
  min-height: 44px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 640px;
  max-width: calc(100vw - 44px);
  height: 640px;
  max-height: calc(100vw - 44px);
  width: min(88vw, 640px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 8px solid #3b281d;
  border-radius: 20px;
  border-radius: clamp(14px, 3vw, 24px);
  box-shadow: inset 0 0 0 2px rgba(255, 247, 236, 0.14), 0 18px 42px var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.square {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
}

.square.light {
  background: #e7c79e;
  background: var(--light-cell);
}

.square.dark {
  background: #7a4b2a;
  background: var(--dark-cell);
}

.square.selected::after,
.square.valid::after {
  position: absolute;
  inset: 10%;
  border-radius: 16px;
  content: "";
  pointer-events: none;
}

.square.selected::after {
  border: 3px solid var(--accent);
}

.square.valid::after {
  background: rgba(139, 209, 124, 0.34);
  box-shadow: inset 0 0 0 3px rgba(139, 209, 124, 0.65);
}

.square.valid {
  cursor: pointer;
}

.piece {
  position: relative;
  width: 76%;
  height: 76%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  box-shadow:
    inset 0 -8px 14px rgba(0, 0, 0, 0.28),
    inset 0 5px 10px rgba(255, 255, 255, 0.2),
    0 10px 18px rgba(0, 0, 0, 0.3);
  transition: transform 150ms ease, filter 150ms ease;
}

.piece.white {
  background: #f2dfc5;
  background: linear-gradient(145deg, #fff8ec, #d8b48d);
}

.piece.black {
  background: #241b15;
  background: linear-gradient(145deg, #48372d, #17110d);
}

.piece.king::before {
  position: absolute;
  inset: 28%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(245, 176, 71, 0.9);
  color: #241a14;
  content: "K";
  font-size: clamp(0.8rem, 2.2vw, 1.2rem);
  font-weight: 900;
}

.piece:active,
.piece.dragging {
  cursor: grabbing;
  filter: brightness(1.08);
  transform: scale(1.04);
}

.drag-ghost {
  position: fixed;
  z-index: 20;
  width: 64px;
  width: var(--ghost-size);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.05);
}

.game-over .board {
  border-color: var(--danger);
}

@media (max-width: 640px) {
  .app {
    padding: 14px;
  }

  .game-panel {
    border-radius: 22px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar > div,
  .topbar button {
    min-height: 52px;
  }

  .board {
    width: calc(100vw - 44px);
    border-width: 5px;
  }
}
