:root {
  color-scheme: dark;
  --bg: #0e1516;
  --panel: #142022;
  --panel-2: #1b2b2e;
  --ink: #f3efe4;
  --muted: #b7c1bc;
  --accent: #f0b45a;
  --accent-2: #7fd0b2;
  --warn: #d97757;
  --light-square: #e3d8c0;
  --dark-square: #7a6a55;
  --active-ring: rgba(127, 208, 178, 0.95);
  --target-ring: rgba(240, 180, 90, 0.95);
  --disabled-wash: rgba(15, 22, 24, 0.62);
  --last-move: rgba(255, 244, 189, 0.5);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.33);
  --radius: 22px;
  --square: min(10vw, 74px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(127, 208, 178, 0.18), transparent 28%),
    linear-gradient(180deg, #0d1717 0%, #091011 100%);
}

.app-shell {
  width: min(1260px, calc(100vw - 32px));
  margin: 24px auto 40px;
}

.hero-card,
.sidebar-card,
.board-panel {
  background: linear-gradient(180deg, rgba(25, 37, 40, 0.96), rgba(16, 24, 26, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 26px;
  align-items: end;
}

.eyebrow,
.panel-label {
  margin: 0 0 8px;
  font-family: "Trebuchet MS", Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  color: var(--accent-2);
}

.hero-copy h1,
.board-header h2 {
  margin: 0;
  font-size: clamp(1.9rem, 3vw, 2.8rem);
}

.hero-text {
  max-width: 58ch;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.hero-controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero-controls label {
  display: grid;
  gap: 6px;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 0.86rem;
  color: var(--muted);
}

button,
select {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  font: inherit;
}

button,
select,
.square {
  transition: transform 120ms ease, background 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

button,
select {
  background: #f0ebe0;
  color: #1f2928;
  cursor: pointer;
}

button:hover,
select:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.layout {
  margin-top: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
}

.board-panel {
  padding: 22px;
}

.board-panel.your-turn {
  border-color: rgba(127, 208, 178, 0.42);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.33), 0 0 0 1px rgba(127, 208, 178, 0.28) inset;
}

.board-panel.your-turn .board-header h2 {
  color: #ecf8f2;
}

.board-panel.your-turn .board-frame {
  box-shadow: inset 0 0 0 1px rgba(127, 208, 178, 0.18);
}

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

.status-badges {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge,
.result-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(240, 180, 90, 0.14);
  color: #ffe5b8;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 0.82rem;
}

.badge-muted {
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.board-frame {
  margin-top: 18px;
  padding: 18px;
  border-radius: 26px;
  background:
    linear-gradient(145deg, rgba(245, 228, 190, 0.08), rgba(0, 0, 0, 0.22)),
    #111a1c;
  overflow: auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, var(--square));
  grid-template-rows: repeat(8, var(--square));
  gap: 4px;
  width: fit-content;
  margin: 0 auto;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--square);
  height: var(--square);
  border-radius: 16px;
  user-select: none;
  cursor: pointer;
  font-size: calc(var(--square) * 0.62);
  overflow: hidden;
}

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

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

.square::before {
  content: attr(data-coord);
  position: absolute;
  left: 8px;
  top: 7px;
  font-size: 0.68rem;
  font-family: "Trebuchet MS", Arial, sans-serif;
  opacity: 0.45;
}

.square .piece {
  position: relative;
  z-index: 2;
  width: calc(var(--square) * 0.8);
  height: calc(var(--square) * 0.8);
  display: block;
  object-fit: contain;
  object-position: center center;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  align-self: center;
  justify-self: center;
  margin: auto;
  transform: translateY(4%);
}

.square .piece-fallback {
  display: grid;
  place-items: center;
  font-size: calc(var(--square) * 0.62);
  line-height: 1;
  align-self: center;
  justify-self: center;
  transform: translateY(4%);
}

.square.selected {
  box-shadow: inset 0 0 0 3px var(--target-ring);
}

.square.target::after,
.square.last-from::after,
.square.last-to::after,
.square.active-piece::after,
.square.moved-piece::after,
.square.locked-piece::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.square.target::after {
  box-shadow: inset 0 0 0 4px var(--target-ring);
}

.square.last-from::after,
.square.last-to::after {
  background: var(--last-move);
}

.square.active-piece::after {
  box-shadow: inset 0 0 0 3px var(--active-ring);
}

.square.moved-piece::after {
  background: rgba(179, 52, 52, 0.26);
  box-shadow: inset 0 0 0 2px rgba(222, 106, 106, 0.72);
}

.square.locked-piece::after {
  background: var(--disabled-wash);
}

.square.moved-piece .piece {
  opacity: 0.92;
}

.square.locked-piece .piece {
  opacity: 0.36;
}

.status-line,
.current-turn {
  color: var(--muted);
  line-height: 1.45;
}

.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}

.status-line {
  flex: 1 1 auto;
  min-height: 48px;
  display: flex;
  align-items: center;
  margin-top: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.board-panel.your-turn .status-line {
  background: rgba(127, 208, 178, 0.16);
  color: #effaf5;
}

.turn-action {
  min-width: 156px;
  padding: 14px 22px;
  background: linear-gradient(180deg, #8fe0bf, #67b897);
  color: #10211d;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 10px 24px rgba(82, 158, 128, 0.28);
}

.turn-action:disabled {
  background: linear-gradient(180deg, #bfd4cb, #9fb3aa);
  color: #41524b;
  opacity: 0.9;
}

.sidebar {
  display: grid;
  gap: 18px;
  align-content: start;
}

.sidebar-card {
  padding: 18px;
}

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

.rules-list li,
.history-list li {
  color: var(--muted);
  line-height: 1.45;
}

.history-list {
  max-height: 430px;
  overflow: auto;
}

.history-list li + li {
  margin-top: 10px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
  margin: 0;
}

.meta-grid dt {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-family: "Trebuchet MS", Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.meta-grid dd {
  margin: 0;
  font-size: 1.05rem;
}

.promotion-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 9, 0.72);
  padding: 20px;
}

.promotion-card {
  width: min(420px, 100%);
  border-radius: 24px;
  padding: 24px;
  background: linear-gradient(180deg, #1b2b2e, #11191b);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
}

.promotion-card h2 {
  margin: 0;
}

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

.promotion-options button {
  width: 100%;
}

.hidden {
  display: none;
}

.current-turn {
  margin-top: 12px;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

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

  .hero-controls {
    justify-content: flex-start;
  }

  .sidebar {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }
}

@media (max-width: 640px) {
  :root {
    --square: min(11vw, 52px);
  }

  .app-shell {
    width: min(100vw - 18px, 100%);
    margin: 12px auto 28px;
  }

  .board-panel,
  .sidebar-card,
  .hero-card {
    padding: 16px;
    border-radius: 18px;
  }

  .board-frame {
    padding: 12px;
  }

  .board-header,
  .history-header {
    align-items: start;
    flex-direction: column;
  }

  .board-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .status-line {
    width: 100%;
  }

  .turn-action {
    width: 100%;
  }

  .status-badges {
    justify-content: flex-start;
  }

  .promotion-options {
    grid-template-columns: 1fr;
  }
}