/* Keep the board and both hands together; ancillary panels use side columns. */
.topbar {
  max-width: none;
  min-height: 56px;
  padding: 8px 16px;
}
.topbar nav {
  gap: 12px;
  align-items: center;
}
.game-layout {
  max-width: none;
  margin: 12px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 220px;
  gap: 16px;
  align-items: start;
}
.arena {
  width: min(100%, max(360px, calc(100dvh + 24px)));
  justify-self: center;
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) 100px;
  gap: 8px;
  align-items: center;
}
.arena,
.mode-sidebar,
.history-sidebar {
  min-width: 0;
}
.mobile-panel-toggle {
  display: none;
}
.turn-banner {
  height: 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  font-size: 18px;
}
.turn-banner strong {
  font-weight: 700;
}
.turn-banner,
.board-toolbar,
#status-detail {
  grid-column: 1 / -1;
}
.reserve-panel {
  grid-column: 3;
  grid-row: 2;
}
.opponent-panel {
  grid-column: 1;
  grid-row: 2;
}
.board-frame {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  border: 2px solid var(--border);
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
}
.square {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  min-height: 0;
  min-width: 0;
  border: 0;
  border-radius: 0;
  border-right: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  background: var(--square);
}
.square:nth-child(8n) {
  border-right: 0;
}
.square:nth-child(n + 57) {
  border-bottom: 0;
}
.square.dark {
  background: var(--square-dark);
}
.square:hover {
  box-shadow: inset 0 0 0 2px var(--border);
}
.square img {
  width: 78%;
  height: 78%;
  z-index: 1;
  pointer-events: none;
}
.coord {
  position: absolute;
  font-size: 14px;
  pointer-events: none;
}
.rank {
  top: 3px;
  left: 4px;
}
.file {
  bottom: 2px;
  right: 4px;
}
.square.last {
  background: var(--last-move);
}
.square.selected {
  box-shadow: inset 0 0 0 3px var(--border);
}
.square.target:after {
  content: "";
  position: absolute;
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: var(--text);
  opacity: 0.5;
  pointer-events: none;
  z-index: 2;
}
.square.target.occupied:after {
  width: 88%;
  height: 88%;
  background: transparent;
  border: 3px dashed var(--border);
  opacity: 1;
}
.square.winning {
  box-shadow: inset 0 0 0 4px var(--border);
}
.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 0;
}
#status-detail {
  margin: 0;
}
.panel {
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  background: var(--surface);
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}
h2 {
  font-size: 18px;
  margin: 0;
}
.mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.mode-tabs button {
  flex: 1;
  padding: 10px 4px;
  white-space: nowrap;
}
.mode-tabs button.active {
  font-weight: 700;
  box-shadow: inset 0 -3px var(--border);
}
.full {
  width: 100%;
}
#join-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
input {
  min-width: 0;
  width: 100%;
  text-transform: uppercase;
}
.room-code {
  font-size: 24px;
  letter-spacing: 4px;
}
#connection {
  margin: 14px 0;
  line-height: 1.5;
}
.reserves {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}
.reserve {
  min-height: 80px;
  padding: 6px 4px;
  position: relative;
  display: grid;
  justify-items: center;
  gap: 2px;
}
.reserve img {
  width: 44px;
  height: 44px;
}
.reserve .count {
  position: absolute;
  right: 3px;
  top: 1px;
}
.reserve.selected {
  box-shadow: inset 0 0 0 2px var(--border);
}
.reserve:disabled img {
  opacity: 0.45;
}
.history-head,
.history-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 6px;
  align-items: center;
}
.history-head {
  border-bottom: 2px solid var(--border);
  padding-bottom: 12px;
}
.history {
  height: clamp(100px, calc(100dvh - 280px), 480px);
  overflow: auto;
  scrollbar-width: thin;
}
.history-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--subtle-border);
}
.history-row img {
  height: 22px;
  width: 22px;
  vertical-align: middle;
}
.move {
  white-space: nowrap;
  font-size: 16px;
}
.empty-history {
  padding: 24px 0;
  text-align: center;
}
.history-actions {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 12px;
  border-top: 2px solid var(--border);
}
.opponent-reserves {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}
#room-queue {
  padding-left: 24px;
  max-height: min(160px, 25dvh);
  overflow-y: auto;
}
#room-queue:empty {
  display: none;
}

/* Keep both hands beside the board, including on compact screens. */
.arena .panel {
  min-width: 0;
  padding: 6px 4px;
}
.arena .panel-title {
  justify-content: center;
  margin: 0 0 8px;
  font-size: 16px;
}
.arena .panel-title h2 {
  display: none;
}
.held-piece {
  position: relative;
  min-height: 80px;
  display: flex;
  align-items: center;
  flex-direction: row;
  justify-content: center;
  gap: 3px;
}
.held-piece span {
  position: absolute;
  top: 1px;
  right: 1px;
}
.held-piece img {
  width: 44px;
  height: 44px;
}
.reserve .name {
  font-size: 16px;
  line-height: 18px;
}
.board-toolbar button {
  padding: 8px;
  flex: 1;
  white-space: nowrap;
}
.history-actions button {
  flex: 1;
  padding: 8px;
  white-space: nowrap;
}
#panel-dialog {
  padding: 16px;
}
#panel-dialog .panel {
  border: 0;
  padding: 0;
}
#panel-dialog .history {
  height: min(45dvh, 400px);
}
#close-panel {
  margin: -8px -8px 8px auto;
}
@media (max-width: 1199px) {
  .topbar {
    padding: 6px 12px;
  }
  .brand {
    font-size: 20px;
  }
  .topbar nav {
    gap: 8px;
  }
  .mobile-panel-toggle {
    display: inline-block;
    padding: 8px;
  }
  .game-layout {
    display: block;
    margin: 8px auto;
    padding: 0 12px;
  }
  .arena {
    margin: auto;
  }
  .mode-sidebar,
  .history-sidebar {
    display: none;
  }
}
@media (max-width: 599px) {
  .game-layout {
    padding: 0 6px;
  }
  .arena {
    grid-template-columns: 72px minmax(0, 1fr) 72px;
    gap: 4px;
  }
  .reserve {
    min-height: 68px;
    padding: 4px 2px;
  }
  .held-piece {
    min-height: 68px;
  }
  .reserve img,
  .held-piece img {
    width: 36px;
    height: 36px;
  }
  .square img {
    width: 85%;
    height: 85%;
  }
  .coord {
    font-size: 12px;
  }
  .rank {
    top: 0;
    left: 1px;
  }
  .file {
    bottom: 0;
    right: 1px;
  }
  .mode-sidebar,
  .history-sidebar {
    display: none;
  }
}

.room-name-form,
.color-options {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.room-name-form input {
  min-width: 0;
  width: 100%;
}
.color-options button {
  flex: 1;
}
.color-options button[aria-pressed="true"] {
  background: var(--text);
  color: var(--surface);
}
#room-players {
  list-style: none;
  padding: 0;
  overflow-wrap: anywhere;
}
#room-players li {
  margin: 8px 0;
}
#room-queue {
  overflow-wrap: anywhere;
}
.room-name-form button {
  flex-shrink: 0;
  white-space: nowrap;
}
.mode-sidebar .mode-panel {
  max-height: calc(100dvh - 88px);
  overflow-y: auto;
}
