:root {
  color-scheme: dark;
  --ink: #f7edf4;
  --muted: #b8c4d8;
  --panel: rgba(13, 18, 29, 0.78);
  --panel-strong: rgba(9, 12, 20, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --rose: #f18dbf;
  --teal: #65d7d0;
  --gold: #f3c46d;
  --danger: #ff6b8b;
  --light-square: #e9d8c7;
  --dark-square: #365b68;
  --light-square-alt: #f2e7d8;
  --dark-square-alt: #274550;
  --selected: rgba(243, 196, 109, 0.62);
  --legal: rgba(101, 215, 208, 0.42);
  --last: rgba(241, 141, 191, 0.38);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(4, 7, 13, 0.52), rgba(4, 7, 13, 0.16), rgba(4, 7, 13, 0.58)),
    linear-gradient(180deg, rgba(6, 9, 16, 0.2), rgba(6, 9, 16, 0.88)),
    url("/static/assets/chess-atmosphere.png") center / cover fixed no-repeat,
    #070a12;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 20px;
  background:
    radial-gradient(circle at 20% 18%, rgba(101, 215, 208, 0.2), transparent 28%),
    radial-gradient(circle at 85% 30%, rgba(241, 141, 191, 0.18), transparent 25%),
    linear-gradient(180deg, rgba(6, 8, 13, 0.1), rgba(6, 8, 13, 0.62));
}

.topbar {
  width: min(1380px, 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow,
.label {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 2.2rem;
  font-weight: 850;
  line-height: 1;
  text-shadow: 0 10px 36px rgba(0, 0, 0, 0.52);
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.match-code {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border: 1px solid var(--line);
  background: rgba(6, 9, 16, 0.64);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
  backdrop-filter: blur(14px);
}

.status-pill.ready {
  color: #dffcf7;
  border-color: rgba(101, 215, 208, 0.48);
  box-shadow: 0 0 22px rgba(101, 215, 208, 0.12);
}

.status-pill.error {
  color: #ffe8ee;
  border-color: rgba(255, 107, 139, 0.55);
}

.game-layout {
  width: min(1380px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(420px, 720px) minmax(230px, 320px);
  gap: 20px;
  align-items: center;
}

.side-panel {
  min-height: 320px;
  padding: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(13, 18, 29, 0.84), rgba(8, 11, 19, 0.74));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

.player-panel,
.history-panel {
  border-radius: 8px;
}

.player-row {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.player-row + .player-row {
  margin-top: 12px;
}

.piece-mark {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 2rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.white-player .piece-mark {
  color: #fff6e8;
  text-shadow: 0 5px 14px rgba(243, 196, 109, 0.34);
}

.black-player .piece-mark {
  color: #0e1620;
  background: linear-gradient(145deg, #f18dbf, #65d7d0);
}

.player-row strong,
.match-stats strong,
.clock-block strong,
.state-block strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 1.02rem;
}

.match-stats {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.match-stats > div,
.clock-block,
.state-block {
  padding: 13px;
  border: 1px solid var(--line);
  background: rgba(6, 9, 16, 0.48);
  border-radius: 8px;
}

.board-section {
  min-width: 0;
}

.turn-banner {
  min-height: 46px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid rgba(101, 215, 208, 0.34);
  background: rgba(8, 12, 20, 0.74);
  border-radius: 8px;
  color: #eefdfc;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 12px 45px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(18px);
}

.board-frame {
  width: min(72vh, 100%);
  max-width: 720px;
  margin: 0 auto;
  aspect-ratio: 1;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    linear-gradient(135deg, rgba(241, 141, 191, 0.5), rgba(101, 215, 208, 0.42)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid rgba(5, 8, 13, 0.62);
  background: #13232b;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  cursor: default;
  color: inherit;
}

.square.light {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.28), transparent),
    var(--light-square);
}

.square.dark {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent),
    var(--dark-square);
}

.square.legal {
  box-shadow: inset 0 0 0 999px var(--legal);
  cursor: pointer;
}

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

.square.last {
  box-shadow: inset 0 0 0 999px var(--last);
}

.square.selected.last,
.square.legal.last {
  box-shadow:
    inset 0 0 0 999px var(--last),
    inset 0 0 0 4px rgba(243, 196, 109, 0.78);
}

.square.selectable {
  cursor: pointer;
}

.piece {
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
  font-size: clamp(2.1rem, 6.4vh, 4.8rem);
  line-height: 1;
  user-select: none;
  transform: translateY(-2px);
  transition:
    transform 140ms ease,
    filter 140ms ease;
}

.square.selectable:hover .piece,
.square.legal:hover .piece {
  transform: translateY(-5px) scale(1.03);
}

.piece.white {
  color: #fff8ee;
  filter:
    drop-shadow(0 2px 1px rgba(255, 255, 255, 0.42))
    drop-shadow(0 10px 12px rgba(28, 21, 16, 0.42));
}

.piece.black {
  color: #111823;
  filter:
    drop-shadow(0 1px 0 rgba(255, 255, 255, 0.24))
    drop-shadow(0 9px 10px rgba(0, 0, 0, 0.42));
}

.coord {
  position: absolute;
  left: 5px;
  bottom: 4px;
  color: rgba(7, 11, 18, 0.56);
  font-size: 0.68rem;
  font-weight: 850;
  pointer-events: none;
}

.dark .coord {
  color: rgba(255, 255, 255, 0.62);
}

.board-actions {
  margin: 12px auto 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.board-actions button,
.promotion-options button {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 9px 14px;
  color: var(--ink);
  background: rgba(9, 13, 22, 0.78);
  font-weight: 800;
  cursor: pointer;
}

.board-actions button:hover,
.promotion-options button:hover {
  border-color: rgba(101, 215, 208, 0.56);
  box-shadow: 0 0 22px rgba(101, 215, 208, 0.16);
}

.board-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.board-actions .danger:hover {
  border-color: rgba(255, 107, 139, 0.7);
  box-shadow: 0 0 22px rgba(255, 107, 139, 0.15);
}

.history-panel {
  display: grid;
  grid-template-rows: auto auto minmax(160px, 1fr);
  gap: 10px;
}

.move-list {
  min-height: 180px;
  max-height: 420px;
  margin: 0;
  padding: 10px 10px 10px 36px;
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(6, 9, 16, 0.45);
  border-radius: 8px;
}

.move-list li {
  margin: 0 0 6px;
  color: #f9edf4;
  font-weight: 700;
}

.move-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.promotion-dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 7, 12, 0.62);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.promotion-dialog[hidden] {
  display: none;
}

.promotion-panel {
  width: min(360px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.promotion-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.promotion-options button {
  min-height: 64px;
  font-size: 2rem;
}

@media (max-width: 1120px) {
  .game-layout {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .side-panel {
    min-height: 0;
  }

  .player-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .player-row + .player-row {
    margin-top: 0;
  }

  .match-stats {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
  }

  .history-panel {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .move-list {
    grid-column: 1 / -1;
    max-height: 220px;
  }
}

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

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

  h1 {
    font-size: 1.8rem;
  }

  .player-panel,
  .match-stats,
  .history-panel {
    grid-template-columns: 1fr;
  }

  .board-frame {
    width: 100%;
    padding: 8px;
  }

  .piece {
    font-size: 2.05rem;
  }

  .coord {
    font-size: 0.58rem;
    left: 3px;
    bottom: 2px;
  }
}
