:root {
  --bg: #0f1216;
  --bg-panel: #171b21;
  --bg-raised: #1e242c;
  --line: #2a323c;
  --text: #e7ebf0;
  --text-dim: #98a3b1;
  --accent: #d99a4e;
  --accent-soft: rgba(217, 154, 78, 0.16);
  --board-light: #e2b872;
  --board-dark: #c8964a;
  --grid: rgba(60, 38, 12, 0.55);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(1100px 600px at 12% -10%, #1b2431 0%, transparent 60%),
    radial-gradient(900px 500px at 105% 5%, #241d1a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 20px 56px;
}

/* ---- masthead ---- */

.masthead {
  margin-bottom: 24px;
}

.masthead h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.masthead p {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---- layout ---- */

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

.stage { min-width: 0; }

/* ---- board ---- */

.board-frame {
  position: relative;
  /* The board is square, so its height tracks its width -- cap the width by the
     viewport height so the whole board stays on screen without scrolling. */
  max-width: min(100%, calc(100vh - 190px));
  margin: 0 auto;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #8c6236, #6d4a28);
  box-shadow: var(--shadow);
  line-height: 0;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

#board.waiting { cursor: progress; }
#board.done { cursor: default; }

/* ---- win banner ---- */

/* Anchored to the foot of the board rather than centred on it: the winning line
   is the thing a player most wants to look at when the game ends. */
.banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 0 18px 22px;
  border-radius: var(--radius);
  background: linear-gradient(to bottom, transparent 45%, rgba(8, 10, 13, 0.7));
  animation: fade 0.3s ease-out;
  pointer-events: none;
  line-height: 1.4;
}

.banner[hidden] { display: none; }

.banner-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  max-width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(23, 27, 33, 0.97);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.banner-text {
  display: flex;
  flex-direction: column;
}

.banner-title {
  font-size: 17px;
  font-weight: 650;
}

.banner-sub {
  color: var(--text-dim);
  font-size: 13px;
}

.banner-card .btn { white-space: nowrap; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---- panel ---- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-panel);
}

.scoreboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--bg-raised);
  transition: border-color 0.18s, background 0.18s;
}

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

.stone {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
}

.stone-black {
  background: radial-gradient(circle at 34% 30%, #6a7079, #14171b 70%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.stone-white {
  background: radial-gradient(circle at 34% 30%, #ffffff, #c3c8ce 72%);
}

.side-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.side-name { font-weight: 600; }

.side-role {
  color: var(--text-dim);
  font-size: 12px;
}

.side-score {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 650;
}

.status {
  margin: 0;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--bg-raised);
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}

.status.thinking::after {
  content: "";
  display: inline-block;
  width: 0;
  animation: dots 1.1s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

/* ---- controls ---- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
}

.field select {
  appearance: none;
  padding: 9px 30px 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-raised)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5 6 8.5l4-4' fill='none' stroke='%2398a3b1' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat right 10px center / 12px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

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

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 3px;
}

.btn {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) { border-color: #3c4756; background: #262e38; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #221606;
}

.btn-primary:hover:not(:disabled) { background: #e6a95e; border-color: transparent; }

/* ---- move history ---- */

.history {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.history-head {
  display: flex;
  justify-content: space-between;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.move-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px 10px;
  margin: 8px 0 0;
  padding: 0 4px 0 0;
  max-height: 168px;
  overflow-y: auto;
  list-style: none;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.move-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  color: var(--text-dim);
}

.move-list li.latest { color: var(--text); font-weight: 600; }

.move-list .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.move-list .dot.black { background: #1b1f25; box-shadow: inset 0 0 0 1px #454d58; }
.move-list .dot.white { background: #dfe3e8; }

.move-list .num { min-width: 22px; color: #6e7987; }

.move-list:empty::after {
  content: "No moves yet";
  color: #6e7987;
  font-size: 13px;
}

.hint {
  margin: 0;
  color: #6e7987;
  font-size: 12px;
  text-align: center;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg-raised);
  font: inherit;
  font-size: 11px;
}

/* ---- narrow screens ---- */

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .app { padding: 22px 14px 40px; }
  .move-list { max-height: 120px; }
  /* Stacked, the board no longer has to share the viewport height with anything,
     so let it use the full column width. */
  .board-frame { max-width: min(100%, 560px); }
}
