:root {
  color-scheme: light dark;
  --background: #f6f4ef;
  --text: #1d1c1a;
  --muted: #6b6760;
  --panel: #ffffff;
  --border: #d9d4ca;
  --board: #dcb35c;
  --line: #3b2f1a;
  --good: #1f7a3a;
  --bad: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #181715;
    --text: #ece9e3;
    --muted: #a29d94;
    --panel: #23211e;
    --border: #3a3732;
    --board: #c49a48;
    --good: #6fcf8a;
    --bad: #f28b82;
  }
}

body {
  margin: 0;
  padding: 24px 16px;
  background: var(--background);
  color: var(--text);
  font-family: system-ui, sans-serif;
}

main {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  max-width: 960px;
  margin: 0 auto;
}

h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

h2 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

header {
  flex-basis: 100%;
}

header p {
  margin: 4px 0;
  max-width: 60ch;
}

nav {
  margin-top: 8px;
}

footer {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 0.9rem;
}

a {
  color: inherit;
}

.board-area {
  display: flex;
  flex: 1 1 340px;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

#board {
  width: 100%;
  max-width: 520px;
  height: auto;
  touch-action: manipulation;
}

#board [data-move] {
  cursor: pointer;
}

#status {
  min-height: 1.5em;
  margin: 12px 0 0;
  font-weight: 600;
  text-align: center;
}

section {
  flex: 1 1 280px;
  min-width: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

label {
  color: var(--muted);
}

select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

button {
  font: inherit;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

#moves {
  max-height: 300px;
  margin: 0;
  padding: 8px 8px 8px 2em;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  font-variant-numeric: tabular-nums;
}

#moves li {
  padding: 1px 0;
}

#moves:empty::before {
  content: "No moves yet.";
  color: var(--muted);
  margin-left: -1.5em;
}

.warning {
  max-width: 960px;
  margin: 0 auto 16px;
  padding: 12px;
  border: 1px solid var(--bad);
  border-radius: 8px;
  color: var(--bad);
}

article section {
  margin-bottom: 8px;
}

article p,
article li {
  max-width: 70ch;
  line-height: 1.5;
}

code {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

body[data-state="thinking"] #status::after {
  content: "";
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-left: 0.5em;
  vertical-align: -0.05em;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

body[data-state="error"] #status {
  color: var(--bad);
}

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

@media (max-width: 720px) {
  .board-area,
  section {
    flex-basis: 100%;
  }

  #board {
    max-width: 100%;
  }
}
