*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #0f1216;
  color: #f5f7fa;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px 12px;
  border-bottom: 1px solid #1c222b;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 28px;
}

.subtle {
  margin: 0;
  color: #9aa6b2;
  font-size: 14px;
}

.status-panel {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #171c22;
  min-width: 220px;
}

.header-toggle {
  background: transparent;
  border: 1px solid #2b3542;
  border-radius: 10px;
  padding: 8px 12px;
  color: #f5f7fa;
  font-weight: 600;
  cursor: pointer;
}

.header-toggle--floating {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  display: none;
}

.header-collapsed .app-header {
  display: none;
}

.header-collapsed .header-toggle--floating {
  display: inline-flex;
}

.status-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.status-row .label {
  color: #8ea0b2;
}

.status-row .value {
  font-weight: 600;
}

.turn-indicator--blue::after,
.turn-indicator--red::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 8px;
}

.turn-indicator--blue::after {
  background: #3d7dff;
}

.turn-indicator--red::after {
  background: #e95454;
}

.app-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  padding: 24px 32px;
  max-width: 1200px;
  margin: 0 auto;
}

.orientation-left-right .app-main {
  align-items: start;
}

.player-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-radius: 16px;
  background: #13171d;
  min-height: 420px;
  min-width: 240px;
}

.orientation-left-right .player-panel {
  margin-top: 18px;
}

.player-panel--red {
  border: 1px solid rgba(238, 90, 90, 0.4);
}

.player-panel--red h2::after,
.player-panel--blue h2::after {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0.2;
}

.player-panel--red h2::after {
  background: #e95454;
}

.player-panel--blue h2::after {
  background: #3d7dff;
}

.turn-red .player-panel--red h2::after,
.turn-blue .player-panel--blue h2::after {
  opacity: 1;
}

.player-panel--blue {
  border: 1px solid rgba(86, 156, 255, 0.4);
}

.board-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.board {
  display: grid;
  gap: 6px;
  background: #101419;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid #1f2630;
  transform-origin: center;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 64px);
  gap: 6px;
}

.board-cell {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px solid #25303c;
  background: #0f141a;
  cursor: pointer;
  position: relative;
  transition: border 0.2s ease, transform 0.2s ease;
}

.show-coords .board-cell::after {
  content: attr(data-row) "," attr(data-col);
  position: absolute;
  bottom: 6px;
  right: 6px;
  font-size: 10px;
  color: #6f7d8c;
}

.orientation-left-right .board {
  transform: rotate(-90deg);
}

.orientation-left-right .card-grid {
  transform: rotate(-90deg);
}

.reserve-card--red .card-grid {
  transform: rotate(180deg);
}

.orientation-left-right .reserve-card--red .card-grid {
  transform: rotate(90deg);
}

.orientation-left-right .piece-token {
  transform: rotate(90deg);
}

.orientation-left-right.show-coords .board-cell::after {
  transform: rotate(90deg);
  transform-origin: center;
}

.board-cell:hover {
  border-color: #3b4757;
  transform: translateY(-1px);
}

.board-cell--temple-red::before,
.board-cell--temple-blue::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.45);
}

.board-cell--temple-red::before {
  background: #e95454;
  box-shadow: 0 0 8px rgba(238, 90, 90, 0.6);
}

.board-cell--temple-blue::before {
  background: #3d7dff;
  box-shadow: 0 0 8px rgba(61, 125, 255, 0.6);
}

.board-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  color: #9aa6b2;
  font-size: 13px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.piece {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  background: #4c5968;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.piece--blue {
  background: #3d7dff;
}

.piece--red {
  background: #e95454;
}

.piece--master {
  border-radius: 6px;
  width: 20px;
  height: 20px;
}

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

.card {
  background: #161b22;
  border-radius: 14px;
  padding: 12px;
  border: 1px solid #202833;
  display: grid;
  gap: 8px;
  min-width: 180px;
  align-items: start;
}

.card-title {
  font-weight: 600;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(5, 16px);
  grid-template-rows: repeat(5, 16px);
  gap: 6px;
  transform: rotate(0deg);
  justify-self: center;
  align-self: start;
  padding: 12px 0 16px;
  margin-top: 6px;
}

.card-cell {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2b3541;
  position: relative;
}

.card-cell--origin {
  background: #404a58;
  box-shadow: 0 0 0 2px #c4cbd5 inset;
}

.card-cell--origin::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f5f7fa;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.card-cell--move {
  background: #8aa6ff;
}

.game-won-blue .board {
  box-shadow:
    0 0 0 2px rgba(86, 156, 255, 0.35),
    0 0 28px rgba(86, 156, 255, 0.22);
}

.game-won-red .board {
  box-shadow:
    0 0 0 2px rgba(238, 90, 90, 0.35),
    0 0 28px rgba(238, 90, 90, 0.22);
}

.piece-token--winner {
  animation: winnerPulse 1.1s ease-in-out infinite;
  transform-origin: center;
}

@keyframes winnerPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.piece-token--loser-dim {
  opacity: 0.55;
  filter: saturate(0.8);
}

.win-banner {
  position: fixed;
  top: 16px;
  left: -100%;
  right: -100%;
  margin: 0 auto;
  max-width: 520px;
  padding: 14px 20px;
  border-radius: 16px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: #f5f7fa;
  background: rgba(20, 26, 33, 0.96);
  border: 1px solid #2b3542;
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}

.win-banner--blue {
  box-shadow: 0 0 24px rgba(61, 125, 255, 0.35);
  border-color: rgba(61, 125, 255, 0.5);
}

.win-banner--red {
  box-shadow: 0 0 24px rgba(238, 90, 90, 0.35);
  border-color: rgba(238, 90, 90, 0.5);
}

.win-banner--show {
  animation: winFlyby 5s ease-in-out forwards;
}

@keyframes winFlyby {
  0% {
    transform: translateX(-30%);
    opacity: 0;
  }
  15% {
    transform: translateX(0%);
    opacity: 1;
  }
  85% {
    transform: translateX(0%);
    opacity: 1;
  }
  100% {
    transform: translateX(30%);
    opacity: 0;
  }
}

.card--selected {
  border-color: #8aa6ff;
  box-shadow: 0 0 0 2px rgba(138, 166, 255, 0.2);
}

.board-cell--selected {
  border-color: #8aa6ff;
  box-shadow: 0 0 0 2px rgba(138, 166, 255, 0.25);
}

.board-cell--legal {
  border-color: #4bd27b;
}

.board-cell--illegal {
  border-color: #e95454;
}

.piece-token {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #0f1216;
  margin: 0 auto;
}

.piece-token--blue {
  background: #3d7dff;
}

.piece-token--red {
  background: #e95454;
}

.piece-token--master {
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 12px;
}

.reserve-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px 32px 32px;
  border-top: 1px solid #1c222b;
}

.card--reserve {
  min-width: 180px;
}

.controls {
  display: grid;
  gap: 8px;
}

.ai-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #202833;
  background: #13171d;
  min-width: 260px;
}

.ai-panel h3 {
  margin: 0;
  font-size: 16px;
}

.ai-row {
  display: grid;
  gap: 8px;
}

.ai-row label {
  font-size: 12px;
  color: #9aa6b2;
}

.ai-row input,
.ai-row select {
  background: #0f141a;
  border: 1px solid #25303c;
  border-radius: 10px;
  padding: 10px 12px;
  color: #f5f7fa;
  font-weight: 600;
}

button {
  background: #1f2732;
  color: #f5f7fa;
  border: 1px solid #2b3542;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  border-color: #3b4757;
}

@media (max-width: 1100px) {
  .app-main {
    grid-template-columns: 1fr;
  }

  .board-row {
    grid-template-columns: repeat(5, 56px);
  }

  .board-cell {
    width: 56px;
    height: 56px;
  }

  .reserve-panel {
    flex-direction: column;
  }
}
