:root {
  --bg-deep: #11181f;
  --bg-mid: #27343f;
  --panel: rgba(246, 238, 227, 0.96);
  --panel-soft: rgba(255, 249, 241, 0.92);
  --ink: #221a15;
  --muted: #665649;
  --line: rgba(44, 32, 24, 0.14);
  --light-square: #e7d7bf;
  --dark-square: #8d6644;
  --dark-square-deep: #6c4d34;
  --gold: #d7a14f;
  --amber: #c46b31;
  --white-piece: #fff8ef;
  --black-piece: #241912;
  --shadow: 0 22px 56px rgba(5, 7, 9, 0.34);
  --cell-size: clamp(42px, 7.8vw, 78px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(215, 161, 79, 0.16), transparent 24%),
    radial-gradient(circle at 82% 14%, rgba(103, 137, 164, 0.18), transparent 22%),
    linear-gradient(150deg, var(--bg-deep), var(--bg-mid));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.026), transparent 28%),
    linear-gradient(rgba(255, 255, 255, 0.014) 0, rgba(255, 255, 255, 0.014) 1px, transparent 1px, transparent 76px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.014) 0, rgba(255, 255, 255, 0.014) 1px, transparent 1px, transparent 76px);
  opacity: 0.35;
  pointer-events: none;
}

.chess-app {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.chess-topbar,
.chess-controls-panel,
.board-panel,
.player-card,
.move-log-card,
.rules-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.chess-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 24px;
}

.chess-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chess-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--ink);
}

.chess-brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--gold), var(--amber));
  color: #23150f;
  font-weight: 900;
}

.chess-brand-copy {
  display: grid;
  gap: 2px;
}

.chess-brand-copy strong {
  font-size: 1.04rem;
}

.chess-brand-copy span {
  color: var(--muted);
  font-size: 0.92rem;
}

.chess-return,
.chess-support,
.action-button,
.board-cell,
.promotion-button {
  font: inherit;
}

.chess-return,
.chess-support,
.action-button,
.promotion-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 999px;
  background: linear-gradient(145deg, #fffaf3, #ecdcc6);
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, border-color 140ms ease;
}

.action-button.primary {
  background: linear-gradient(145deg, var(--gold), var(--amber));
  color: #23150f;
}

.chess-support {
  background: linear-gradient(145deg, #ffdc42, #f0b90a);
  color: #23150f;
}

.chess-return:hover,
.chess-return:focus-visible,
.chess-support:hover,
.chess-support:focus-visible,
.action-button:hover,
.action-button:focus-visible,
.promotion-button:hover,
.promotion-button:focus-visible,
.board-cell:hover,
.board-cell:focus-visible {
  transform: translateY(-1px);
}

.action-button:disabled,
.board-cell:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chess-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr);
  gap: 20px;
  align-items: start;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 12px;
  color: rgba(255, 247, 235, 0.78);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.chess-copy h1,
.status-copy h2,
.rules-card h3,
.move-log-card h3,
.result-overlay h2,
.promotion-dialog h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

.chess-copy h1 {
  margin: 0 0 14px;
  max-width: 10ch;
  color: #fff7eb;
  font-size: clamp(2.3rem, 5vw, 4.6rem);
  line-height: 0.95;
}

.chess-copy p:last-child {
  margin: 0;
  max-width: 60ch;
  color: rgba(255, 244, 231, 0.84);
  line-height: 1.65;
}

.chess-controls-panel {
  border-radius: 30px;
  padding: 22px;
}

.status-copy h2 {
  margin: 0;
  font-size: clamp(1.26rem, 2.4vw, 1.82rem);
  line-height: 1.12;
}

.notice-text,
.mode-hint,
.promotion-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.58;
}

.setup-panel {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.setup-group {
  display: grid;
  gap: 12px;
}

.setup-label {
  margin: 0;
  color: #584635;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.choice-pill {
  position: relative;
  display: inline-flex;
  min-height: 48px;
  align-items: center;
}

.choice-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-pill span {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 999px;
  background: #fbf4ea;
  color: #4f3f2f;
  font-weight: 800;
  cursor: pointer;
}

.choice-pill input:checked + span {
  background: linear-gradient(145deg, rgba(215, 161, 79, 0.2), rgba(255, 246, 231, 0.94));
  border-color: rgba(196, 107, 49, 0.28);
  color: #3a281a;
}

.difficulty-field {
  display: grid;
  gap: 10px;
}

.difficulty-select {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 16px;
  background: #fbf4ea;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

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

.metric-card {
  padding: 14px;
  border: 1px solid rgba(36, 25, 18, 0.1);
  border-radius: 20px;
  background: var(--panel-soft);
}

.metric-card span {
  display: block;
  margin-bottom: 6px;
  color: #786452;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 1.28rem;
}

.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.chess-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(300px, 0.82fr);
  gap: 20px;
  align-items: start;
}

.board-panel {
  position: relative;
  border-radius: 34px;
  padding: 20px;
  background:
    radial-gradient(circle at top, rgba(255, 246, 231, 0.16), transparent 24%),
    linear-gradient(155deg, #5b3822, #2e1a10);
  overflow: hidden;
}

.board-shell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 14px;
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 32%),
    linear-gradient(145deg, #9a6b44, #603b25);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.08),
    inset 0 -8px 14px rgba(24, 12, 6, 0.24);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, var(--cell-size));
  width: max-content;
  max-width: 100%;
  border-radius: 18px;
  overflow: hidden;
}

.board-cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0;
  padding: 0;
  background: transparent;
}

.board-cell.light {
  background: linear-gradient(145deg, var(--light-square), #e1ccb0);
}

.board-cell.dark {
  background: linear-gradient(145deg, var(--dark-square), var(--dark-square-deep));
}

.board-cell.selected::before,
.board-cell.last-move::after,
.board-cell.in-check::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 14px;
}

.board-cell.selected::before {
  border: 4px solid rgba(215, 161, 79, 0.95);
  box-shadow: 0 0 0 3px rgba(34, 26, 21, 0.32) inset;
}

.board-cell.move-target::before,
.board-cell.capture-target::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.board-cell.move-target::before {
  width: calc(var(--cell-size) * 0.24);
  height: calc(var(--cell-size) * 0.24);
  border-radius: 50%;
  background: rgba(250, 244, 232, 0.82);
}

.board-cell.capture-target::before {
  inset: 8px;
  border: 4px solid rgba(250, 244, 232, 0.84);
  border-radius: 50%;
}

.board-cell.last-move::after {
  border: 3px solid rgba(255, 227, 169, 0.78);
}

.board-cell.in-check::before {
  border: 4px solid rgba(201, 82, 60, 0.9);
  box-shadow: 0 0 0 3px rgba(81, 22, 14, 0.24) inset;
}

.piece-symbol {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.7rem, 4vw, 2.8rem);
  line-height: 1;
  user-select: none;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.22));
}

.piece-symbol.white {
  color: var(--white-piece);
  text-shadow:
    -1px -1px 0 rgba(77, 54, 38, 0.4),
    1px -1px 0 rgba(77, 54, 38, 0.4),
    -1px 1px 0 rgba(77, 54, 38, 0.4),
    1px 1px 0 rgba(77, 54, 38, 0.4);
}

.piece-symbol.black {
  color: var(--black-piece);
  text-shadow:
    -1px -1px 0 rgba(255, 246, 232, 0.24),
    1px -1px 0 rgba(255, 246, 232, 0.24),
    -1px 1px 0 rgba(255, 246, 232, 0.24),
    1px 1px 0 rgba(255, 246, 232, 0.24);
}

.result-overlay,
.promotion-dialog {
  position: absolute;
  left: 50%;
  width: min(92%, 440px);
  padding: 22px 20px 18px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 249, 241, 0.97), rgba(253, 244, 232, 0.98)),
    var(--panel);
  text-align: center;
  box-shadow: 0 22px 48px rgba(12, 5, 2, 0.36);
  z-index: 5;
}

.promotion-dialog {
  top: 26px;
}

.result-overlay {
  top: 50%;
  transform: translate(-50%, -50%);
}

.result-overlay[hidden] {
  display: none;
}

.overlay-kicker {
  margin: 0 0 6px;
  color: #7c654f;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.result-overlay h2,
.promotion-dialog h2 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  line-height: 1;
}

.overlay-message {
  margin: 0 auto;
  max-width: 30ch;
  color: var(--muted);
  line-height: 1.58;
}

.overlay-stats,
.overlay-actions,
.promotion-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.overlay-stats span {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: #f4e9da;
  color: #594537;
  font-weight: 700;
}

.promotion-button {
  min-width: 120px;
  min-height: 68px;
  border-radius: 22px;
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: #fbf4ea;
}

.promotion-button span:last-child {
  font-weight: 800;
}

.promotion-symbol {
  font-size: 2rem;
  line-height: 1;
}

.chess-sidebar {
  display: grid;
  gap: 16px;
}

.player-card,
.move-log-card,
.rules-card {
  border-radius: 28px;
  padding: 18px;
}

.player-card {
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.34), transparent 46%),
    var(--panel);
}

.player-card.active {
  border-color: rgba(215, 161, 79, 0.4);
  box-shadow:
    var(--shadow),
    0 0 0 2px rgba(215, 161, 79, 0.14) inset;
}

.player-card.winner {
  border-color: rgba(86, 142, 111, 0.42);
  box-shadow:
    var(--shadow),
    0 0 0 2px rgba(86, 142, 111, 0.16) inset;
}

.player-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.player-piece {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 2rem;
}

.player-piece.white {
  background: #f9efe0;
  color: var(--black-piece);
}

.player-piece.black {
  background: #241912;
  color: #f8efdf;
}

.player-name {
  margin: 0 0 4px;
  font-size: 1.08rem;
  font-weight: 800;
}

.player-role {
  margin: 0;
  color: var(--muted);
}

.player-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0 0;
}

.player-stats div {
  padding: 12px;
  border-radius: 18px;
  background: var(--panel-soft);
  border: 1px solid rgba(36, 25, 18, 0.08);
}

.player-stats dt {
  margin: 0 0 6px;
  color: #7a6654;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.player-stats dd {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.move-log-card h3,
.rules-card h3 {
  margin: 0;
  font-size: 1.28rem;
}

.card-head span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.move-log-list,
.rules-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.move-log-list {
  display: grid;
  gap: 10px;
}

.move-log-item,
.move-log-empty {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--panel-soft);
  border: 1px solid rgba(36, 25, 18, 0.08);
}

.move-log-empty {
  grid-template-columns: 1fr;
  color: var(--muted);
}

.move-number {
  color: #7b674e;
  font-weight: 800;
}

.move-entry {
  min-width: 0;
  font-weight: 700;
}

.rules-list {
  display: grid;
  gap: 10px;
}

.rules-list li {
  color: var(--muted);
  line-height: 1.58;
  padding-left: 18px;
  position: relative;
}

.rules-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--amber));
  transform: translateY(-50%);
}

@media (max-width: 1080px) {
  .chess-hero,
  .chess-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .chess-app {
    width: min(100%, calc(100% - 20px));
    padding-top: 14px;
  }

  .chess-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .chess-topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .chess-topbar-actions > * {
    flex: 1 1 0;
  }

  .metric-grid,
  .player-stats {
    grid-template-columns: 1fr;
  }

  .board-panel,
  .chess-controls-panel,
  .player-card,
  .move-log-card,
  .rules-card {
    padding: 16px;
  }

  .board-shell {
    padding: 10px;
    overflow-x: auto;
  }

  .board-grid {
    min-width: calc(var(--cell-size) * 8);
  }

  .promotion-button {
    min-width: calc(50% - 10px);
  }

  .move-log-item {
    grid-template-columns: 34px 1fr 1fr;
  }
}
