:root {
  --bg: #1c1f24;
  --panel: #262b33;
  --text: #e8eaed;
  --muted: #9aa3af;
  --accent: #3d8bfd;
  --accent-hover: #5a9cff;
  --error: #ff6b6b;
  --ok: #8fd19e;
  --border: #3a424e;
  --input: #15181d;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a3340 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #243028 0%, transparent 50%),
    var(--bg);
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.header-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.user-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.user-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.user-nav a:hover {
  color: var(--text);
}

.page.narrow {
  max-width: 520px;
}

.tagline {
  margin: 0.4rem 0 1.75rem;
  color: var(--muted);
}

.setup-form,
.panel,
.games-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.games-section {
  margin-bottom: 1.25rem;
}

.games-section h2,
.setup h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.games-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.game-card {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.9rem 1rem;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.game-meta h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.game-meta p {
  margin: 0.15rem 0;
}

.history-preview {
  color: var(--text);
  font-size: 0.92rem;
  word-break: break-word;
}

.game-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex-shrink: 0;
}

a.button,
.button {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #323843;
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
}

a.button.primary,
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.danger {
  background: #4a2428;
  border-color: #7a3a42;
  color: #ffd5d8;
}

button.danger:hover {
  border-color: #b04b56;
}

.banner-error {
  margin: 0 0 1rem;
}

.back-link {
  margin: 0 0 0.35rem;
}

.back-link a {
  color: var(--muted);
  text-decoration: none;
}

.back-link a:hover {
  color: var(--text);
}

.setup {
  margin-top: 0;
}

.setup-form input[type="text"] {
  margin-bottom: 1rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
}

legend {
  padding: 0 0.35rem;
  color: var(--muted);
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-right: 1.25rem;
  cursor: pointer;
}

.history-label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
}

textarea,
input[type="text"] {
  width: 100%;
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  font: inherit;
}

textarea {
  resize: vertical;
  margin-bottom: 1rem;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #323843;
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
}

button:hover {
  border-color: #556070;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.game {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.board-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem;
  display: flex;
  justify-content: center;
}

.board-wrap svg {
  max-width: 100%;
  height: auto;
}

.status p {
  margin: 0 0 0.35rem;
}

.message {
  color: var(--ok);
}

.error {
  color: var(--error);
}

.move-form {
  margin: 1rem 0;
}

.move-form label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 0.5rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.history-box {
  margin: 1rem 0;
  padding: 0.75rem 0.85rem;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.history-box h2,
.suggestions h2 {
  margin: 0 0 0.6rem;
  font-size: 1.05rem;
}

.history-text {
  margin: 0;
  line-height: 1.45;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

.suggestion-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 0.5rem;
}

.suggestion {
  width: 100%;
  text-align: left;
  display: block;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.suggestion:hover:not(:disabled) {
  border-color: var(--accent);
  background: #1a2230;
}

.suggestion:disabled {
  opacity: 0.55;
  cursor: default;
}

.suggestion .line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.suggestion .eval {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.35rem;
  display: block;
}

.plies-legend {
  display: flex;
  gap: 0.5rem;
  margin: 0 0 0.7rem;
  font-size: 0.85rem;
}

.ply {
  display: inline-block;
  padding: 0.12rem 0.4rem;
  border-radius: 5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.ply-you {
  background: rgba(61, 139, 253, 0.22);
  color: #b7d4ff;
  border: 1px solid rgba(61, 139, 253, 0.35);
}

.ply-opp {
  background: rgba(154, 163, 175, 0.14);
  color: #c5ccd6;
  border: 1px solid rgba(154, 163, 175, 0.28);
}

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

.loader {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.loader[hidden] {
  display: none !important;
}

.loader-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  min-width: 180px;
  text-align: center;
}

.loader-card p {
  margin: 0.75rem 0 0;
  color: var(--muted);
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid #3a424e;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

body.is-loading {
  cursor: progress;
}

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

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