:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --board-move-highlight: rgba(255, 221, 46, 0.62);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1rem;
  background: #1b1b1b;
  color: #f0f0f0;
  display: flex;
  justify-content: center;
}

.app {
  width: min(100%, 920px);
  display: grid;
  gap: 1rem;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(220px, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.board-wrap {
  width: 100%;
  margin-inline: 0;
}

.board-player-avatar {
  width: 5.2rem;
  height: 3.2rem;
  display: grid;
  place-items: center;
  margin-right: auto;
  border: none;
  border-radius: 12px;
  background: transparent;
  font-size: 3.2rem;
  line-height: 1;
}

.board-player-box {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.28rem;
}

.board-player-box .board-player-avatar {
  margin-right: 0;
}

.board-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.2rem 0.4rem;
  border-radius: 10px;
  background: var(--team-row-bg, rgba(70, 70, 70, 0.22));
  margin-bottom: 0.25rem;
}

.board-player-avatar-top {
  margin-bottom: 0;
}

.board-player-avatar-bottom {
  margin-top: 0;
}

.player-captured-material {
  min-height: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.14rem;
  margin-top: 0;
  font-size: 0.78rem;
  line-height: 1;
  opacity: 0.95;
}

.captured-piece-icon {
  display: inline-block;
  line-height: 1;
}

.captured-material-lead {
  margin-left: 0.2rem;
  font-size: 0.74rem;
  font-weight: 600;
  opacity: 0.92;
}

.board-bottom-bar {
  margin-top: 0.25rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0.2rem 0.4rem;
  border-radius: 10px;
  background: var(--team-row-bg, rgba(70, 70, 70, 0.22));
}

.board-player-avatar-bottom {
  grid-column: 1;
  justify-self: start;
}

.board-player-box-bottom {
  grid-column: 1;
  justify-self: start;
}

.move-confirm-controls {
  grid-column: 2;
  display: flex;
  gap: 0.55rem;
  justify-self: center;
}

.move-confirm-controls.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.move-confirm-controls button {
  min-width: 3rem;
}

#move-confirm {
  background: #2f5a3a;
  border-color: #4f8a60;
}

.player-timer {
  grid-column: 3;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  font-variant-numeric: tabular-nums;
  font-size: 1.18rem;
  font-weight: 600;
  opacity: 0.96;
  padding: 0.18rem 0.45rem;
  border: 1px solid #4d4d4d;
  border-radius: 7px;
  background: #343434;
  line-height: 1.2;
}

#bottom-player-timer-icon {
  color: inherit;
}

.player-timer.is-warning-on {
  color: #ffd87a;
}

.move-log-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.board-container {
  position: static;
}

#board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  overflow: hidden;
  background: linear-gradient(135deg, #2a2a2a, #222222);
}

#board::before {
  content: "";
  position: absolute;
  inset: 0;
}

#board.is-ready::before {
  content: none;
}

.board-sound-button {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
}

.playback-controls {
  margin-top: 0.45rem;
  margin-bottom: 0.55rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.move-log-header {
  display: grid;
  grid-template-columns: 2.2rem 1fr 2.2rem;
  align-items: center;
  gap: 0.45rem;
}

.move-log-header #view-prev-game {
  grid-column: 1;
}

.move-log-header #move-log-title {
  grid-column: 2;
  text-align: center;
}

.move-log-header #view-next-game {
  grid-column: 3;
}

.move-log-game-nav {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 8px;
  border: 1px solid #4a4a4a;
  background: #2f2f2f;
  color: #f0f0f0;
  display: grid;
  place-items: center;
  text-decoration: none;
}

.move-log-game-nav:hover {
  background: #3a3a3a;
}

.move-log-game-nav i {
  pointer-events: none;
}

.playback-nav {
  display: flex;
  gap: 0.55rem;
}

.playback-controls button {
  min-width: 3rem;
  touch-action: manipulation;
}

.playback-controls button i,
.board-sound-button i {
  pointer-events: none;
}

.playback-controls button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cm-chessboard use.piece {
  opacity: 0.92;
}

#board.review-mode use.piece {
  opacity: 0.68;
}

#board.game-over use.piece {
  opacity: 0.82;
}

#board.game-over-draw use.piece {
  opacity: 0.74;
}

.panel {
  background: #262626;
  border: 1px solid #3b3b3b;
  border-radius: 10px;
  padding: 0.8rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.controls-spaced {
  margin-top: 0.6rem;
}

.controls label {
  font-size: 0.9rem;
  opacity: 0.9;
}

button,
select,
input {
  font: inherit;
}

button,
select {
  border-radius: 8px;
  border: 1px solid #4a4a4a;
  background: #2f2f2f;
  color: #f0f0f0;
  padding: 0.45rem 0.7rem;
}

#toggle-sound[aria-pressed="true"] {
  background: #434343;
  border-color: #707070;
}

.status {
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.8rem;
}

.field label {
  font-size: 0.85rem;
  opacity: 0.85;
}

.field input {
  width: 100%;
  border: 1px solid #4a4a4a;
  background: #1e1e1e;
  color: #e9e9e9;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  box-sizing: border-box;
}

.field textarea {
  width: 100%;
  min-height: 150px;
  border: 1px solid #4a4a4a;
  background: #1e1e1e;
  color: #e9e9e9;
  border-radius: 8px;
  padding: 0.55rem;
  box-sizing: border-box;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.35;
}

.json-feedback {
  min-height: 1.1rem;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  opacity: 0.9;
}

.json-feedback.error {
  color: #ff9595;
}

.json-feedback.ok {
  color: #a7e1a8;
}

.move-log-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  margin-top: 0;
  border: 1px solid #3b3b3b;
  border-radius: 8px;
  background: #202020;
}

.move-log-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.move-log-col-number {
  width: 2.6rem;
}

.move-log-col-flag {
  width: 1.5rem;
}

.move-log-table th,
.move-log-table td {
  padding: 0.35rem 0.45rem;
  font-size: 0.9rem;
  line-height: 1.35;
  border-bottom: 1px solid #343434;
}

.move-log-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #252525;
  text-align: left;
  font-weight: 600;
}

.move-log-table th:first-child,
.move-log-number {
  text-align: right;
  color: #b9b9b9;
}

.move-log-flag {
  text-align: center;
}

.move-log-flag {
  padding-left: 0.2rem !important;
  padding-right: 0.2rem !important;
}

.move-log-flag-icon {
  display: inline-block;
  font-size: 1.4rem;
  line-height: 1;
}

.move-log-white {
  padding-left: 0.25rem !important;
  text-decoration: underline;
  text-decoration-color: var(--team-white-color, #ff9f2f);
  text-decoration-thickness: 1px;
  text-decoration-skip-ink: none;
  text-underline-offset: 0.18em;
}

.move-log-black {
  padding-left: 0.25rem !important;
  text-decoration: underline;
  text-decoration-color: var(--team-black-color, #2fc6c0);
  text-decoration-thickness: 1px;
  text-decoration-skip-ink: none;
  text-underline-offset: 0.18em;
}

.move-log-white,
.move-log-black {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.move-log-active {
  background: rgba(255, 221, 46, 0.12);
  font-weight: 600;
}

.move-log-future {
  opacity: 0.45;
}

.move-log-table tbody tr:last-child td {
  border-bottom: none;
}

.license {
  font-size: 0.8rem;
  opacity: 0.8;
}

.cm-chessboard .last-move-overlay {
  fill: var(--board-move-highlight) !important;
}

.cm-chessboard .square.mated-king-square {
  fill: #8c2f2f !important;
}

.cm-chessboard .square.illegal-start-square {
  fill: rgba(180, 45, 45, 0.72) !important;
}

.cm-chessboard .square.start-square-selected {
  fill: var(--board-move-highlight) !important;
}

.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 0.65rem;
  z-index: 1000;
}

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

.result-card {
  position: relative;
  width: min(100%, 420px);
  background: #1f1f1f;
  border: 1px solid #5e5e5e;
  border-radius: 12px;
  padding: 1rem 1rem 0.9rem;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.result-close {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid #6b6b6b;
  background: #2a2a2a;
  color: #f2f2f2;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.result-title {
  margin: 0.3rem 0 0.25rem;
  font-size: 1.3rem;
}

.result-score {
  margin: 0;
  font-weight: 700;
  font-size: 1.2rem;
  color: #ffdc91;
}

.result-detail {
  margin: 0.55rem 0 0.1rem;
  opacity: 0.9;
}

@media (max-width: 640px) {
  body {
    padding: 0.45rem;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 0.6rem;
  }

  .move-log-wrap {
    flex: none;
    max-height: 230px;
  }
}
