:root {
  color-scheme: dark;
  --bg: #151613;
  --panel: #232820;
  --panel-2: #30372d;
  --line: rgba(255, 255, 255, 0.14);
  --text: #f6f0df;
  --muted: #bdb6a2;
  --gold: #e3bc67;
  --crimson: #c6453f;
  --crimson-dark: #6f1e23;
  --iron: #7fb1af;
  --iron-dark: #284a51;
  --light-square: #d6c092;
  --dark-square: #44583b;
  --dark-square-2: #394b33;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(120deg, rgba(198, 69, 63, 0.18), transparent 38%),
    linear-gradient(320deg, rgba(127, 177, 175, 0.18), transparent 42%),
    radial-gradient(circle at 50% 0%, rgba(227, 188, 103, 0.12), transparent 34%),
    var(--bg);
  color: var(--text);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--crimson) 0 48%, transparent 48% 52%, var(--iron) 52%),
    #242721;
  box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.15);
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 1.2rem + 1.1vw, 2.35rem);
  line-height: 1.03;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #2a2f28;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.icon-button:hover {
  border-color: rgba(227, 188, 103, 0.66);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.board-panel,
.side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(35, 40, 32, 0.92);
  box-shadow: var(--shadow);
}

.board-panel {
  padding: 14px;
}

.status-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 12px;
  margin-bottom: 14px;
}

.status-strip > div,
.score-tile,
.mode-panel,
.captured-strip,
.log-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
}

.status-strip > div {
  min-width: 0;
  padding: 10px 12px;
}

.eyebrow,
.score-name,
.log-title {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  line-height: 1.2;
}

.status-strip strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.board-wrap {
  width: min(76vh, 100%);
  margin: 0 auto;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #1e241c;
  box-shadow: inset 0 0 32px rgba(0, 0, 0, 0.42);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  color: inherit;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 52%),
    var(--dark-square);
  cursor: pointer;
}

.square.dark:nth-child(odd) {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent 52%),
    var(--dark-square-2);
}

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

.square.move-target::after,
.square.capture-target::after {
  content: "";
  position: absolute;
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(246, 240, 223, 0.42);
  box-shadow: 0 0 0 7px rgba(246, 240, 223, 0.12);
}

.square.capture-target::after {
  width: 42%;
  background: rgba(227, 188, 103, 0.62);
  box-shadow: 0 0 0 8px rgba(198, 69, 63, 0.2);
}

.piece {
  position: relative;
  width: 72%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  box-shadow:
    inset 0 6px 9px rgba(255, 255, 255, 0.2),
    inset 0 -10px 12px rgba(0, 0, 0, 0.32),
    0 9px 14px rgba(0, 0, 0, 0.35);
  transition:
    transform 160ms ease,
    filter 160ms ease;
}

.piece::before {
  content: "";
  position: absolute;
  inset: 17%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.24);
}

.piece::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}

.piece.crimson {
  background: radial-gradient(circle at 35% 28%, #f19983, var(--crimson) 42%, var(--crimson-dark));
}

.piece.iron {
  background: radial-gradient(circle at 35% 28%, #d7eeee, var(--iron) 38%, var(--iron-dark));
}

.piece.king::after {
  inset: 28%;
  clip-path: polygon(50% 0, 63% 35%, 100% 35%, 70% 58%, 82% 100%, 50% 74%, 18% 100%, 30% 58%, 0 35%, 37% 35%);
  border-radius: 0;
  background: #f2d37d;
}

.piece:hover,
.piece.is-active {
  transform: translateY(-3px);
  filter: brightness(1.08);
}

.piece.faded {
  opacity: 0;
}

.side-panel {
  padding: 14px;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score-tile {
  min-height: 86px;
  padding: 12px;
}

.score-tile strong {
  display: block;
  margin-top: 8px;
  font-size: 2.05rem;
  line-height: 1;
}

.mode-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding: 12px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.mode-button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mode-button:hover {
  color: var(--text);
}

.mode-button.is-active {
  border-color: rgba(227, 188, 103, 0.46);
  background: rgba(227, 188, 103, 0.14);
  color: var(--text);
}

.mode-panel strong {
  display: block;
  overflow-wrap: anywhere;
}

.crimson-score {
  border-color: rgba(198, 69, 63, 0.42);
}

.iron-score {
  border-color: rgba(127, 177, 175, 0.42);
}

.captured-strip {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 12px;
  color: var(--muted);
}

.captured-strip strong {
  color: var(--text);
}

.log-panel {
  margin-top: 10px;
  padding: 12px;
}

.log-title {
  margin-bottom: 10px;
}

#battleLog {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

#battleLog li::marker {
  color: var(--gold);
}

.battle-scene {
  position: absolute;
  left: calc((var(--battle-col) + 0.5) * 12.5%);
  top: calc((var(--battle-row) + 0.5) * 12.5%);
  z-index: 20;
  width: 30%;
  aspect-ratio: 1.35;
  pointer-events: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.34));
}

.battle-flash {
  position: absolute;
  inset: 12% 2%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(246, 240, 223, 0.92), rgba(227, 188, 103, 0.2) 42%, transparent 68%);
  opacity: 0;
  animation: clashFlash 1800ms ease-out forwards;
}

.knight {
  position: absolute;
  bottom: 5%;
  width: 56%;
  height: 82%;
  object-fit: contain;
}

.knight.attacker {
  left: -5%;
  animation: attackerStrike 1800ms cubic-bezier(0.2, 0.78, 0.28, 1) forwards;
}

.knight.defender {
  right: -5%;
  transform: scaleX(-1);
  animation: defenderStrike 1800ms cubic-bezier(0.2, 0.78, 0.28, 1) forwards;
}

.slash {
  position: absolute;
  left: 34%;
  top: 15%;
  width: 44%;
  height: 70%;
  border-radius: 50%;
  border-top: 5px solid rgba(255, 238, 170, 0.95);
  border-right: 3px solid rgba(255, 238, 170, 0.56);
  opacity: 0;
  transform: rotate(-26deg) scale(0.6);
  animation: slashArc 1800ms ease-out forwards;
}

.spark {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffe28f;
  opacity: 0;
  animation: sparkPop 1800ms ease-out forwards;
}

.spark:nth-child(5) {
  transform: translate(-14px, -8px);
}

.spark:nth-child(6) {
  transform: translate(16px, -10px);
  animation-delay: 125ms;
}

.spark:nth-child(7) {
  transform: translate(4px, 15px);
  animation-delay: 220ms;
}

@keyframes attackerStrike {
  0% {
    transform: translateX(-22%) rotate(-6deg);
  }
  44% {
    transform: translateX(28%) rotate(10deg);
  }
  68% {
    transform: translateX(10%) rotate(-2deg);
  }
  100% {
    transform: translateX(18%) rotate(0);
  }
}

@keyframes defenderStrike {
  0% {
    transform: translateX(22%) scaleX(-1) rotate(-6deg);
  }
  44% {
    transform: translateX(-28%) scaleX(-1) rotate(10deg);
  }
  72% {
    transform: translateX(-12%) scaleX(-1) rotate(-3deg);
    opacity: 1;
  }
  100% {
    transform: translateX(-20%) scaleX(-1) rotate(-10deg);
    opacity: 0.28;
  }
}

@keyframes clashFlash {
  32% {
    opacity: 0;
    transform: scale(0.4);
  }
  48% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

@keyframes slashArc {
  34% {
    opacity: 0;
    transform: rotate(-48deg) scale(0.4);
  }
  52% {
    opacity: 1;
    transform: rotate(28deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: rotate(44deg) scale(1.18);
  }
}

@keyframes sparkPop {
  44% {
    opacity: 0;
  }
  55% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    margin-left: 18px;
    margin-top: -14px;
  }
}

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

  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .captured-strip,
  .mode-panel,
  .log-panel {
    margin-top: 0;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding: 12px 0;
  }

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

  .icon-button {
    width: 100%;
  }

  .status-strip,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .board-panel,
  .side-panel {
    padding: 10px;
  }

  .battle-scene {
    width: 40%;
  }
}
