html {
  font-size: 14px;
  position: relative;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  min-height: 100vh;
  background: var(--bs-tertiary-bg);
}

.modal,
.dropdown-menu,
.list-group {
  --bs-modal-bg: var(--bs-tertiary-bg);
  --bs-modal-border-color: var(--bs-border-color);
  --bs-modal-header-border-color: var(--bs-border-color);
  --bs-modal-footer-border-color: var(--bs-border-color);
  --bs-dropdown-bg: var(--bs-tertiary-bg);
  --bs-dropdown-border-color: var(--bs-border-color);
  --bs-list-group-bg: var(--bs-tertiary-bg);
  --bs-list-group-border-color: var(--bs-border-color);
}

.modal-content,
.dropdown-menu,
.list-group-item {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
}

.form-select option {
  background-color: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
}

.theme-switch {
  min-height: 2rem;
  padding-left: 2.75rem;
}

.theme-switch .form-check-input {
  height: 1.15rem;
  margin-left: -2.75rem;
  width: 2.2rem;
}

.theme-switch .form-check-label {
  color: var(--bs-secondary-color);
  line-height: 1.95rem;
  white-space: nowrap;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--bs-primary);
}

.chess-board {
  aspect-ratio: 1;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.play-board-column {
  --play-board-max-size: min(100%, calc(100svh - 12rem));
}

.play-board-column .chess-board {
  margin-inline: auto;
  width: var(--play-board-max-size);
  max-width: 100%;
}

.match-board-shell {
  margin-inline: auto;
  width: var(--play-board-max-size);
  max-width: 100%;
}

.match-board-shell .chess-board {
  width: 100%;
}

.match-player-strip {
  align-items: center;
  display: flex;
  justify-content: space-between;
  min-height: 3.25rem;
  padding-block: 0.45rem;
}

.match-player-identity {
  align-items: baseline;
  display: flex;
  gap: 0.45rem;
  min-width: 0;
}

.match-player-name {
  font-weight: 700;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-player-rating {
  color: var(--bs-secondary-color);
  font-size: 0.9rem;
  white-space: nowrap;
}

.match-player-meta {
  align-items: center;
  display: flex;
  gap: 0.65rem;
}

.match-clock {
  font-size: 1.2rem;
  font-weight: 700;
}

.turn-indicator {
  background-color: transparent;
  border: 1px solid var(--bs-border-color);
  border-radius: 50%;
  display: inline-block;
  height: 0.8rem;
  width: 0.8rem;
}

.turn-indicator.active {
  background-color: var(--bs-success);
  border-color: var(--bs-success);
}

.play-layout {
  align-items: flex-start;
}

.analysis-layout {
  align-items: flex-start;
}

.analysis-board-column {
  --analysis-board-max-size: min(100%, calc(100svh - 14.5rem));
}

.analysis-board-column .match-board-shell {
  width: var(--analysis-board-max-size);
}

.analysis-board-column .match-player-strip {
  min-height: 2.4rem;
  padding-block: 0.25rem;
}

.analysis-player-strip {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
}

.analysis-player-identity {
  min-width: 0;
}

.analysis-player-strip #topPlayerName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-player-meta {
  align-items: center;
  display: flex;
  gap: 0.65rem;
  justify-self: end;
  min-width: 0;
}

.analysis-bottom-player-identity {
  justify-self: end;
}

.analysis-bottom-player-strip {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
}

.analysis-game-controls > .btn {
  align-items: center;
  display: inline-flex;
  height: 2rem;
  justify-content: center;
  padding-inline: 0;
  width: 2.25rem;
}

.analysis-action-column {
  align-items: center;
  display: flex;
  justify-content: flex-start;
}

.play-action-column {
  align-items: center;
  display: flex;
  justify-content: flex-start;
}

.play-board-actions {
  flex-direction: column;
}

.play-board-actions > .btn {
  border-radius: var(--bs-btn-border-radius);
  height: 2.5rem;
  width: 2.75rem;
}

.play-board-actions > .btn + .btn {
  margin-left: 0;
  margin-top: 0.5rem;
}

@media (max-width: 991.98px) {
  .analysis-board-column {
    --analysis-board-max-size: min(100%, calc(100svh - 10rem));
  }

  .analysis-action-column {
    justify-content: center;
  }

  .analysis-bottom-player-strip {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .analysis-game-controls {
    justify-self: center;
  }

  .analysis-game-controls > .btn {
    width: 2rem;
  }

  .play-board-column {
    --play-board-max-size: min(100%, calc(100svh - 9rem));
  }

  .play-action-column {
    justify-content: center;
  }

  .play-board-actions {
    flex-direction: row;
  }

  .play-board-actions > .btn + .btn {
    margin-left: 0.5rem;
    margin-top: 0;
  }
}

@media (max-height: 560px) {
  .analysis-board-column {
    --analysis-board-max-size: min(100%, calc(100svh - 8rem));
  }

  .play-board-column {
    --play-board-max-size: min(100%, calc(100svh - 7rem));
  }
}

.move-list {
  max-height: 26rem;
  overflow: auto;
}

.matchmaking-shell {
  max-width: 72rem;
}

.matchmaking-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.matchmaking-square {
  align-content: space-between;
  aspect-ratio: 1;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.5rem;
  color: var(--bs-body-color);
  cursor: pointer;
  display: grid;
  font: inherit;
  min-height: 12rem;
  padding: 1rem;
  text-decoration: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.matchmaking-square:hover,
.matchmaking-square:focus {
  border-color: rgba(var(--bs-primary-rgb), 0.65);
  box-shadow: 0 0.75rem 2rem rgba(var(--bs-body-color-rgb), 0.08);
  color: var(--bs-body-color);
  transform: translateY(-2px);
}

.matchmaking-square-category {
  color: var(--bs-secondary-color);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.matchmaking-square-title {
  font-size: 1.35rem;
  font-weight: 700;
}

.matchmaking-square-control {
  font-family: var(--bs-font-monospace);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.matchmaking-square-footer {
  align-items: center;
  color: var(--bs-secondary-color);
  display: flex;
  font-size: 0.9rem;
  justify-content: space-between;
}

.engine-output {
  min-height: 14rem;
}

[data-bs-theme="dark"] .table:not(.opening-move-table) {
  --bs-table-bg: var(--bs-body-bg);
  --bs-table-color: var(--bs-body-color);
  --bs-table-border-color: var(--bs-border-color);
  --bs-table-striped-bg: var(--bs-tertiary-bg);
  --bs-table-hover-bg: var(--bs-tertiary-bg);
  --bs-table-hover-color: var(--bs-body-color);
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .table:not(.opening-move-table) > :not(caption) > * > * {
  background-color: var(--bs-table-bg);
  color: var(--bs-table-color);
}

[data-bs-theme="dark"] .table-hover:not(.opening-move-table) > tbody > tr:hover > * {
  background-color: var(--bs-table-hover-bg);
  color: var(--bs-table-hover-color);
}

.opening-move-table {
  --bs-table-bg: transparent;
  --bs-table-border-color: transparent;
  width: auto;
}

.opening-move-table > :not(caption) > * > * {
  background-color: transparent;
  box-shadow: none;
}

.opening-move-table td {
  border: 0;
  padding: 0.125rem 0.2rem;
  white-space: nowrap;
}

.opening-move-number {
  background-color: transparent;
  width: 2.25rem;
}

.opening-move {
  --bs-btn-bg: transparent;
  --bs-btn-active-bg: transparent;
  --bs-btn-disabled-bg: transparent;
  --bs-btn-hover-bg: rgba(var(--bs-body-color-rgb), 0.06);
  min-width: 4.5rem;
  padding-inline: 0.45rem;
  text-align: left;
}

.opening-move.btn-primary,
.opening-move.btn-primary.active,
.opening-move.btn-outline-primary.active,
.opening-move.btn-outline-secondary.active {
  background-color: transparent;
  border-color: var(--bs-primary);
  color: var(--bs-primary);
  font-weight: 600;
}

body.board-theme-brown cg-board {
  background-color: #f0d9b5;
}

body.board-theme-green cg-board {
  background-color: #eeeed2;
  background-image: linear-gradient(45deg, #769656 25%, transparent 25%),
    linear-gradient(-45deg, #769656 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #769656 75%),
    linear-gradient(-45deg, transparent 75%, #769656 75%);
  background-position: 0 0, 0 50%, 50% -50%, -50% 0;
  background-size: 25% 25%;
}

body.board-theme-blue cg-board {
  background-color: #dee3e6;
  background-image: linear-gradient(45deg, #8ca2ad 25%, transparent 25%),
    linear-gradient(-45deg, #8ca2ad 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8ca2ad 75%),
    linear-gradient(-45deg, transparent 75%, #8ca2ad 75%);
  background-position: 0 0, 0 50%, 50% -50%, -50% 0;
  background-size: 25% 25%;
}

body.board-theme-gray cg-board {
  background-color: #d7d7d7;
  background-image: linear-gradient(45deg, #8f8f8f 25%, transparent 25%),
    linear-gradient(-45deg, #8f8f8f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #8f8f8f 75%),
    linear-gradient(-45deg, transparent 75%, #8f8f8f 75%);
  background-position: 0 0, 0 50%, 50% -50%, -50% 0;
  background-size: 25% 25%;
}

body.board-theme-midnight cg-board {
  background-color: #c5cad3;
  background-image: linear-gradient(45deg, #4b5668 25%, transparent 25%),
    linear-gradient(-45deg, #4b5668 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #4b5668 75%),
    linear-gradient(-45deg, transparent 75%, #4b5668 75%);
  background-position: 0 0, 0 50%, 50% -50%, -50% 0;
  background-size: 25% 25%;
}
