:root {
  --bg: #f4efe3;
  --panel: rgba(255, 250, 240, 0.84);
  --panel-strong: #fdf8f0;
  --ink: #1f1a17;
  --muted: #6c6258;
  --accent: #b76935;
  --accent-deep: #8f4f27;
  --board-dark: #7b5941;
  --board-light: #f3d8b6;
  --board-border: #3a271a;
  --select: rgba(255, 194, 92, 0.95);
  --move: rgba(60, 140, 91, 0.32);
  --capture: rgba(178, 43, 43, 0.56);
  --check: rgba(189, 28, 28, 0.8);
  --shadow: 0 24px 60px rgba(46, 31, 20, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 210, 141, 0.55), transparent 30%),
    radial-gradient(circle at bottom right, rgba(122, 82, 48, 0.18), transparent 28%),
    linear-gradient(145deg, #efe5d3 0%, #e4d5bf 45%, #d5b996 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
  opacity: 0.3;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(320px, 1fr) minmax(240px, 320px);
  gap: 24px;
  padding: 24px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

.hero-panel,
.sidebar-card,
.board-frame {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(86, 61, 37, 0.12);
  box-shadow: var(--shadow);
}

.hero-panel,
.sidebar-card {
  border-radius: 28px;
  padding: 24px;
}

.eyebrow,
.label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  color: var(--muted);
}

.hero-panel h1,
.sidebar-heading h2,
.status-card h2,
.promotion-dialog h2 {
  font-family: "Cinzel", serif;
}

.hero-panel h1 {
  margin: 10px 0 14px;
  font-size: clamp(2rem, 3vw, 3.25rem);
  line-height: 1.05;
}

.hero-copy,
.detail-text,
.rules-list,
.promotion-dialog p {
  color: var(--muted);
  line-height: 1.6;
}

.detail-text {
  min-height: 52px;
}

.status-card {
  margin-top: 28px;
  padding: 20px;
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(248, 234, 213, 0.8));
  border: 1px solid rgba(143, 79, 39, 0.16);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 146px;
}

.status-card > div {
  flex: 1;
}

.status-card h2 {
  margin: 8px 0 8px;
  font-size: 1.45rem;
}

.reset-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(183, 105, 53, 0.28);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.reset-button:hover,
.reset-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 16px 32px rgba(183, 105, 53, 0.34);
}

.legend-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.legend-card {
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 248, 240, 0.72);
  border: 1px solid rgba(86, 61, 37, 0.08);
}

.legend-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1rem;
}

.board-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: start;
}

.board-frame {
  width: min(84vmin, 780px);
  padding: 18px;
  border-radius: 30px;
  background:
    linear-gradient(160deg, rgba(255, 251, 245, 0.95), rgba(232, 213, 188, 0.88));
}

.board-header,
.sidebar-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.board-header {
  padding: 4px 6px 16px;
  color: var(--muted);
  font-weight: 600;
}

.turn-pill {
  min-width: 78px;
  text-align: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(183, 105, 53, 0.12);
  color: var(--accent-deep);
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 22px;
  border: 10px solid var(--board-border);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  padding: 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 0;
}

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

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

.square::before,
.square::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.square.selected::before {
  inset: 0;
  box-shadow: inset 0 0 0 5px var(--select);
}

.square.legal::after,
.square.capture::after {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 999px;
}

.square.legal::after {
  width: 24%;
  height: 24%;
  background: var(--move);
}

.square.capture::after {
  width: 76%;
  height: 76%;
  border: 4px solid var(--capture);
  background: radial-gradient(circle, transparent 62%, rgba(178, 43, 43, 0.12) 63%);
}

.square.in-check::before {
  inset: 0;
  box-shadow: inset 0 0 0 5px var(--check);
}

.square-label {
  position: absolute;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.9;
  pointer-events: none;
}

.square-label.file {
  right: 8px;
  bottom: 6px;
}

.square-label.rank {
  left: 8px;
  top: 6px;
}

.square.light .square-label {
  color: rgba(91, 53, 26, 0.78);
}

.square.dark .square-label {
  color: rgba(255, 239, 214, 0.82);
}

.piece {
  width: 82%;
  height: 82%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.22));
}

.sidebar {
  display: grid;
  gap: 24px;
  align-self: start;
}

.sidebar-heading h2 {
  margin: 0;
  font-size: 1.25rem;
}

.sidebar-heading span {
  color: var(--muted);
  font-size: 0.92rem;
}

.move-list {
  margin: 18px 0 0;
  padding-left: 24px;
  max-height: 420px;
  overflow: auto;
  line-height: 1.7;
}

.move-list li {
  padding-right: 8px;
}

.rules-list {
  margin: 18px 0 0;
  padding-left: 20px;
}

.promotion-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(35, 23, 14, 0.55);
  padding: 20px;
  z-index: 20;
}

.promotion-modal.hidden {
  display: none;
}

.promotion-dialog {
  width: min(92vw, 520px);
  border-radius: 28px;
  padding: 28px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.promotion-dialog h2 {
  margin: 0 0 10px;
}

.promotion-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.promotion-choice {
  border: 1px solid rgba(86, 61, 37, 0.12);
  border-radius: 20px;
  background: rgba(255, 248, 240, 0.9);
  padding: 14px;
  cursor: pointer;
}

.promotion-choice img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.promotion-choice span {
  display: block;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .board-frame {
    width: min(92vw, 760px);
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
    gap: 16px;
  }

  .status-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .legend-grid,
  .sidebar {
    grid-template-columns: 1fr;
  }

  .board {
    border-width: 8px;
  }

  .square.capture::after {
    width: 82%;
    height: 82%;
    border-width: 3px;
  }
}
