:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #a3e635;
  --accent-ink: #1a2e05;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.45);
  --speed: 180ms;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2a4a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.tagline {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ---------- buttons ---------- */
.btn {
  min-height: 40px;
  min-width: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--speed),
    border-color var(--speed),
    transform var(--speed),
    color var(--speed);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: #475569;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn:focus-visible,
.board:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-accent:hover:not(:disabled) {
  background: #bef264;
  border-color: #bef264;
}

.btn.armed {
  background: #7f1d1d;
  border-color: #b91c1c;
}

.btn-lang {
  min-width: 48px;
}

/* ---------- layout ---------- */
.layout {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 4px 16px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
  align-content: start;
}

.board-wrap {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.board {
  display: block;
  width: min(100%, calc(100vh - 130px));
  min-width: 260px;
  aspect-ratio: 1;
  border-radius: 14px;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.55),
    0 2px 0 rgba(255, 255, 255, 0.06) inset;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.coords {
  fill: #5b3d17;
  font: 600 15px system-ui, sans-serif;
}

/* Bigger boards are drawn smaller on screen, so their labels get a larger viewBox size. */
.coords-13 {
  font-size: 18px;
}

.coords-19 {
  font-size: 22px;
  letter-spacing: -1px;
}

.move-num {
  font: 700 16px system-ui, sans-serif;
}

.captured-mark {
  fill: none;
  stroke: #7f1d1d;
  stroke-width: 2.5;
  stroke-dasharray: 4 4;
  opacity: 0.75;
}

.pending-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  animation: pulse 1s ease-in-out infinite;
}

.cursor {
  fill: rgba(163, 230, 53, 0.12);
  stroke: var(--accent);
  stroke-width: 3;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* ---------- side panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition:
    border-color var(--speed),
    box-shadow var(--speed);
  min-width: 0;
}

.player.active {
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px var(--accent),
    var(--shadow);
}

.dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-black {
  background: radial-gradient(circle at 35% 30%, #6b7280, #0b0f19 70%);
}

.dot-white {
  background: radial-gradient(circle at 35% 30%, #fff, #b9bec7 80%);
}

.pname {
  font-weight: 700;
}

.who,
.pstat {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  font-weight: 600;
}

.message {
  min-height: 1.45em;
  color: var(--muted);
  font-size: 0.92rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.spinner[hidden] {
  display: none;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions .btn {
  flex: 1 1 auto;
  padding: 8px 10px;
  white-space: nowrap;
}

.scoring {
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--accent);
}

.scoring[hidden] {
  display: none;
}

.scoring p {
  margin: 0 0 8px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row.end {
  justify-content: flex-end;
}

.options {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 12px;
}

.options[open] {
  padding-bottom: 12px;
}

.options summary {
  cursor: pointer;
  min-height: 40px;
  display: flex;
  align-items: center;
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.file-btn {
  position: relative;
  overflow: hidden;
}

.file-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

/* ---------- dialogs ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 20px;
}

.dialog::backdrop {
  background: rgba(2, 6, 23, 0.7);
}

.dialog h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}

fieldset {
  border: 0;
  margin: 0 0 12px;
  padding: 0;
}

legend,
.field > span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.seg {
  display: flex;
  gap: 6px;
}

.seg label {
  flex: 1;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-weight: 600;
  text-align: center;
  transition:
    background var(--speed),
    border-color var(--speed);
}

.seg input:checked + span {
  border-color: var(--accent);
  background: rgba(163, 230, 53, 0.14);
  color: var(--accent);
}

.seg input:focus-visible + span {
  outline: 2px solid var(--accent);
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.field select {
  width: 100%;
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  padding: 6px 10px;
}

.field select:disabled {
  opacity: 0.45;
}

.result-line {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 12px;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.score-table[hidden] {
  display: none;
}

.score-table th,
.score-table td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}

.score-table th:first-child {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
}

.score-table .total th,
.score-table .total td {
  font-weight: 800;
  border-bottom: 0;
}

/* ---------- footer ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 16px 18px;
}

.footer a {
  color: var(--accent);
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .board {
    width: min(100%, 640px);
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .tagline {
    display: none;
  }

  .topbar {
    padding: 8px 16px;
  }

  .player {
    padding: 8px 10px;
  }

  .actions .btn {
    font-size: 0.88rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
