:root {
  --bg: #0d0e10;
  --panel: #17191c;
  --line: #23262a;
  --text: #e8e8ea;
  --muted: #7d838c;
  --accent: #4f8ef7;
  --black-disc: #08090a;
  --black-ring: #2c2f34;
  --white-disc: #e8e8ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  width: min(92vw, 560px);
  padding: 40px 0 56px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

main.arena-page {
  width: min(94vw, 900px);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: -4px;
}

.tab {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid transparent;
}

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

.tab.active {
  color: var(--text);
  border-color: var(--line);
  background: var(--panel);
}

header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.side {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  transition: border-color 0.15s ease, color 0.15s ease;
}

.side.active {
  border-color: var(--accent);
  color: var(--text);
}

.side .count {
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: center;
}

.side .disc {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.side-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.side .name {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.side.active .name {
  color: var(--text);
}

.disc.black {
  background: var(--black-disc);
  box-shadow: inset 0 0 0 1px var(--black-ring);
}

.disc.white {
  background: var(--white-disc);
}

.status {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
  padding: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 4px;
  aspect-ratio: 1;
  width: 100%;
}

.cell {
  position: relative;
  background: var(--panel);
  border: 0;
  padding: 0;
  cursor: default;
  display: grid;
  place-items: center;
}

.cell.legal {
  cursor: pointer;
}

.cell.legal::after {
  content: "";
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.28;
  transition: opacity 0.15s ease;
}

.cell.legal:hover::after {
  opacity: 0.65;
}

.cell.last {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.stone {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  animation: place 0.14s ease-out;
}

.stone.black {
  background: var(--black-disc);
  box-shadow: inset 0 0 0 1px var(--black-ring);
}

.stone.white {
  background: var(--white-disc);
}

@keyframes place {
  from {
    transform: scale(0.7);
    opacity: 0.4;
  }
}

.stone.flip-to-black,
.stone.flip-to-white {
  animation-duration: 0.26s;
  animation-timing-function: ease-in-out;
  animation-fill-mode: both;
}

.stone.flip-to-black {
  animation-name: flip-to-black;
}

.stone.flip-to-white {
  animation-name: flip-to-white;
}

@keyframes flip-to-black {
  0% {
    transform: scaleX(1);
    background: var(--white-disc);
    box-shadow: none;
  }
  50% {
    transform: scaleX(0.05);
    background: var(--white-disc);
    box-shadow: none;
  }
  51% {
    transform: scaleX(0.05);
    background: var(--black-disc);
    box-shadow: inset 0 0 0 1px var(--black-ring);
  }
  100% {
    transform: scaleX(1);
    background: var(--black-disc);
    box-shadow: inset 0 0 0 1px var(--black-ring);
  }
}

@keyframes flip-to-white {
  0% {
    transform: scaleX(1);
    background: var(--black-disc);
    box-shadow: inset 0 0 0 1px var(--black-ring);
  }
  50% {
    transform: scaleX(0.05);
    background: var(--black-disc);
    box-shadow: inset 0 0 0 1px var(--black-ring);
  }
  51% {
    transform: scaleX(0.05);
    background: var(--white-disc);
    box-shadow: none;
  }
  100% {
    transform: scaleX(1);
    background: var(--white-disc);
    box-shadow: none;
  }
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

button,
select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

button:hover:not(:disabled),
select:hover {
  border-color: #33373d;
}

button:disabled {
  color: var(--muted);
  cursor: default;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

label[hidden] {
  display: none;
}

.sims {
  margin-left: auto;
}

.sims b {
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.eval {
  margin: 0;
  min-height: 1.5em;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.busy .cell.legal {
  cursor: progress;
}

.toggle-fight {
  border-color: #1f8a4c;
  color: #4fd489;
}

.toggle-fight:hover:not(:disabled) {
  border-color: #29a75d;
}

.toggle-fight.running {
  border-color: #a73333;
  color: #f06a6a;
}

.toggle-fight.running:hover {
  border-color: #c23e3e;
}

.arena {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 180px;
  gap: 20px;
  align-items: start;
}

.arena-board {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.fighter {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.fighter h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fighter h2 .disc {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.fighter label {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.fighter select {
  width: 100%;
}

@media (max-width: 680px) {
  .arena {
    grid-template-columns: 1fr;
  }

  .arena-board {
    order: -1;
  }
}
