/*
  Classic Board Games: a felt card table with wooden boards and paper panels.
  Shared site chrome (bar, footer, fonts) comes from ../shared/gh.css.
*/

:root {
  color-scheme: light;
  --felt: #1f4d3c;
  --felt-deep: #163a2d;
  --felt-light: #2a5f4b;
  --felt-text: #f1ead8;
  --felt-muted: #b9c8bd;
  --paper: #f7f1e3;
  --paper-raised: #fffaf0;
  --ink: #22201b;
  --muted: #6b6455;
  --line: #ddd2bb;
  --line-strong: #b8aa8c;
  --accent: #b8432f;
  --accent-deep: #963322;
  --brass: #d9a63a;
  --wood: #e1b56a;
  --wood-deep: #b98a43;
  --wood-line: #8c6a35;
  --target: #2e8b6e;
  --last: #e4572e;
  --win: #ffd166;
  --radius: 10px;
  --shadow-panel: 0 1px 0 rgba(0, 0, 0, 0.08), 0 18px 36px -18px rgba(0, 0, 0, 0.55);
  --shadow-board: 0 2px 0 rgba(0, 0, 0, 0.12), 0 24px 48px -20px rgba(0, 0, 0, 0.6);
  --font: var(--gh-font-body);
  --display: var(--gh-font-display);

  /* Player colors; each board kind overrides them. */
  --p1: radial-gradient(circle at 35% 30%, #5b6068, #15181c 70%);
  --p2: radial-gradient(circle at 35% 30%, #ffffff, #d8d2c3 75%);
  --p1-flat: #1d2024;
  --p2-flat: #ece6d8;
}

:where(*, *::before, *::after) {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--felt-text);
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.07), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.35), transparent 60%),
    var(--felt);
  background-attachment: fixed;
  font-family: var(--font);
  line-height: 1.6;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  line-height: 1.1;
  text-wrap: balance;
}

p {
  margin: 0;
}

:where(a, button, summary):focus-visible {
  outline: 3px solid var(--brass);
  outline-offset: 2px;
}

.table {
  width: min(1240px, 100% - 2 * var(--gh-gutter));
  margin-inline: auto;
}

/* ---------- Buttons and controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-raised);
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  border-color: var(--accent-deep);
  color: #fff;
  background: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
}

.btn-on-felt {
  border-color: rgba(241, 234, 216, 0.35);
  color: var(--felt-text);
  background: rgba(0, 0, 0, 0.18);
}

.btn-on-felt:hover:not(:disabled) {
  border-color: var(--felt-text);
}

.segmented {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #ece4d1;
}

.segmented button {
  min-height: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 0.9375rem;
  font-weight: 650;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  color: var(--ink);
  background: var(--paper-raised);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

/* ---------- Overview page ---------- */

.lobby-head {
  max-width: 46em;
  padding-block: clamp(32px, 6vw, 72px) clamp(24px, 4vw, 40px);
}

.lobby-head h1 {
  font-size: clamp(2.5rem, 1.5rem + 4vw, 4.4rem);
}

.lobby-head p {
  max-width: 36em;
  margin-top: 16px;
  color: var(--felt-muted);
  font-size: clamp(1.02rem, 0.95rem + 0.3vw, 1.15rem);
  text-wrap: pretty;
}

.lobby {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lobby li {
  display: grid;
}

.lobby a {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 16px;
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow-panel);
  text-decoration: none;
  transition: transform 160ms ease;
}

.lobby a:hover {
  transform: translateY(-2px);
}

.lobby svg {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.lobby h2 {
  font-size: 1.6rem;
}

.lobby .sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.lobby p {
  margin-top: 8px;
  color: #4a4438;
  font-size: 0.9375rem;
  line-height: 1.55;
}

.lobby .meta {
  display: block;
  margin-top: 10px;
  color: var(--accent);
  font-size: 0.8125rem;
  font-weight: 700;
}

.lobby-notes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
  margin-top: clamp(40px, 6vw, 64px);
  padding-top: 28px;
  border-top: 1px solid rgba(241, 234, 216, 0.2);
}

.lobby-notes h2 {
  font-size: 1.4rem;
}

.lobby-notes p {
  margin-top: 8px;
  color: var(--felt-muted);
  font-size: 0.9375rem;
}

/* ---------- Match page ---------- */

.match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: clamp(20px, 3vw, 36px);
  padding-block: 20px 8px;
}

.match-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
}

.match-head h1 {
  font-size: clamp(2rem, 1.5rem + 2vw, 2.9rem);
}

.match-head p {
  color: var(--felt-muted);
  font-size: 0.9375rem;
}

/* The two players face each other above the board; the side to move is lit. */
.players {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 14px 8px 10px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  transition: border-color 200ms ease, background-color 200ms ease;
}

.player.is-ai {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.player.is-turn {
  border-color: var(--brass);
  background: rgba(0, 0, 0, 0.32);
}

.player .swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(241, 234, 216, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
}

.player .swatch.p1 {
  background: var(--p1);
}

.player .swatch.p2 {
  background: var(--p2);
}

.player .who {
  min-width: 0;
  line-height: 1.25;
}

.player .who strong {
  display: block;
  font-size: 1rem;
}

.player .who span {
  display: block;
  overflow: hidden;
  color: var(--felt-muted);
  font-size: 0.8125rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.player .count {
  font-family: var(--display);
  font-size: 1.7rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.versus {
  color: var(--felt-muted);
  font-family: var(--display);
  font-size: 1.1rem;
}

.status {
  min-height: 1.6em;
  margin-top: 12px;
  color: var(--felt-text);
  font-weight: 650;
  text-align: center;
}

.status .thinking::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
  --animation-reduced: none;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

@media (prefers-reduced-motion: reduce) {
  .status .thinking::after {
    animation: none;
    content: "…";
  }
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  margin-top: 14px;
  padding: clamp(12px, 2.4vw, 28px);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.16);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.25);
}

.board-fit {
  --fit: min(100%, var(--board-max, 620px), max(300px, (100dvh - 300px) * var(--aspect, 1)));
  width: var(--fit);
}

@supports not (height: 100dvh) {
  .board-fit {
    --fit: min(100%, var(--board-max, 620px), max(300px, (100vh - 300px) * var(--aspect, 1)));
  }
}

/* Per-game board size and piece colors. */
[data-kind="connect6"] .board-fit { --board-max: 720px; }
[data-kind="four-in-a-row"] .board-fit { --board-max: 600px; --aspect: 1.15; }
[data-kind="dots-and-boxes"] .board-fit { --board-max: 500px; }
[data-kind="hex"] .board-fit { --board-max: 760px; --aspect: 1.55; }
[data-kind="mancala"] .board-fit { --board-max: 880px; --aspect: 2.35; }
[data-kind="nine-mens-morris"] .board-fit { --board-max: 560px; }
[data-kind="ataxx"] .board-fit { --board-max: 560px; }

[data-kind="four-in-a-row"] {
  --p1: radial-gradient(circle at 35% 30%, #f07a63, #c7321f 70%);
  --p2: radial-gradient(circle at 35% 30%, #ffe27a, #e5a90f 70%);
  --p1-flat: #d8432f;
  --p2-flat: #f2c230;
}

[data-kind="checkers"],
[data-kind="breakthrough"],
[data-kind="nine-mens-morris"] {
  --p1: radial-gradient(circle at 35% 30%, #5d5a55, #1f1d1a 70%);
  --p2: radial-gradient(circle at 35% 30%, #ef7a62, #b3321f 70%);
  --p1-flat: #26231f;
  --p2-flat: #c0412d;
}

[data-kind="hex"],
[data-kind="ataxx"],
[data-kind="dots-and-boxes"] {
  --p1: radial-gradient(circle at 35% 30%, #ef7a62, #b3321f 70%);
  --p2: radial-gradient(circle at 35% 30%, #6f9ee0, #2456a6 70%);
  --p1-flat: #c8432f;
  --p2-flat: #2f64b5;
}

[data-kind="ataxx"] .piece {
  border-radius: 22%;
  width: 78%;
}

.match-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

/* Side column: paper panels. */
.side {
  display: grid;
  gap: 16px;
  color: var(--ink);
}

.panel {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow-panel);
}

.panel h2 {
  font-size: 1.35rem;
}

.field {
  margin-top: 14px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 650;
}

.record {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.875rem;
}

.record strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.move-log {
  max-height: 168px;
  margin: 10px 0 0;
  padding: 0;
  overflow: auto;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  list-style: none;
}

.move-log li {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  border-top: 1px dashed var(--line);
}

.move-log li:first-child {
  color: var(--ink);
  font-weight: 650;
}

.move-log .n {
  min-width: 2.2em;
  color: var(--line-strong);
}

.rules summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--display);
  font-size: 1.35rem;
  line-height: 1.2;
  cursor: pointer;
  list-style: none;
}

.rules summary::-webkit-details-marker {
  display: none;
}

.rules summary::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 160ms ease;
}

.rules[open] summary::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}

.rules ol,
.rules ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding-inline-start: 1.25em;
  color: #4a4438;
  font-size: 0.9375rem;
}

.rules h3 {
  margin-top: 18px;
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 700;
}

/* Result card floats over the final position; "View board" hides it. */
.result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: inherit;
  background: rgba(10, 24, 18, 0.45);
  animation: fade-in 220ms ease both;
}

.result[hidden] {
  display: none;
}

.result-card {
  width: min(360px, 100%);
  padding: 24px;
  border-radius: 14px;
  color: var(--ink);
  background: var(--paper-raised);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7);
  text-align: center;
  animation: rise 260ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.result-card h2 {
  font-size: 2.2rem;
}

.result-card.is-win h2 {
  color: var(--accent);
}

.result-card p {
  margin-top: 8px;
  color: var(--muted);
}

.result-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.result-actions .btn-link {
  min-height: 40px;
  border: 0;
  color: var(--muted);
  background: none;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
}

@media (prefers-reduced-motion: reduce) {
  .result,
  .result-card {
    animation: none;
  }
}

/* ---------- Pieces ---------- */

.piece {
  position: relative;
  display: block;
  width: 84%;
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35), inset 0 -2px 3px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.piece.p1 {
  background: var(--p1);
}

.piece.p2 {
  background: var(--p2);
}

.piece.king::after {
  content: "";
  position: absolute;
  inset: 26%;
  border: 2px solid var(--brass);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.is-last > .piece,
.piece.is-last {
  animation: place 260ms cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

.is-flipped > .piece {
  animation: flip 360ms ease both;
}

@keyframes place {
  from { transform: scale(0.4); opacity: 0.2; }
}

@keyframes flip {
  0% { transform: scaleX(1); }
  50% { transform: scaleX(0.1); }
  100% { transform: scaleX(1); }
}

/* A small dot marks the most recent move; a ring marks where a piece left. */
.is-last > .piece::before {
  content: "";
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  background: var(--last);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.85);
}

.is-from::before {
  content: "";
  position: absolute;
  inset: 22%;
  border: 2px dashed rgba(228, 87, 46, 0.85);
  border-radius: 50%;
  pointer-events: none;
}

.is-win > .piece {
  box-shadow: 0 0 0 3px var(--win), 0 0 16px 4px rgba(255, 209, 102, 0.7);
}

@media (prefers-reduced-motion: reduce) {
  .is-last > .piece,
  .piece.is-last,
  .is-flipped > .piece {
    animation: none;
  }
}

/* ---------- Intersection boards (Gomoku, Capture Five, Connect6) ---------- */

.goban {
  --n: 15;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  aspect-ratio: 1;
  padding: calc(100% / var(--n) / 4);
  border-radius: 6px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 50%),
    var(--wood);
  box-shadow: var(--shadow-board), inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.pt {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

/* Grid lines are drawn by each point so the edges stop at the outer stones. */
.pt::before,
.pt::after {
  content: "";
  position: absolute;
  background: var(--wood-line);
  pointer-events: none;
}

.pt::before {
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
}

.pt::after {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
}

.pt.c0::before { left: 50%; }
.pt.cN::before { right: 50%; }
.pt.r0::after { top: 50%; }
.pt.rN::after { bottom: 50%; }

.pt.star > .dot {
  position: absolute;
  width: 18%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--wood-line);
}

.pt > .piece {
  z-index: 1;
  width: 90%;
}

.pt[aria-disabled="true"] {
  cursor: default;
}

/* Ghost stone under the pointer on empty points. */
@media (hover: hover) {
  .goban.is-live .pt.is-open:hover > .ghost {
    position: absolute;
    z-index: 1;
    width: 90%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--you);
    opacity: 0.45;
  }
}

.pt.is-draft > .ghost {
  position: absolute;
  z-index: 1;
  width: 90%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--you);
  opacity: 0.6;
  box-shadow: 0 0 0 2px var(--brass);
}

/* ---------- Square boards (Reversi, Checkers, Ataxx, Breakthrough, LOA) ---------- */

.squares {
  --n: 8;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  aspect-ratio: 1;
  overflow: hidden;
  border: 6px solid #5b3d22;
  border-radius: 6px;
  box-shadow: var(--shadow-board);
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: #ead9b5;
  cursor: pointer;
}

.sq.dark {
  background: #a3743f;
}

.squares.reversi {
  border-color: #234a32;
  background: #1f6a43;
}

.squares.reversi .sq {
  background: #2c7d50;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.35);
}

.squares.plain .sq {
  background: #e9dfc8;
  box-shadow: inset 0 0 0 0.5px rgba(80, 60, 30, 0.3);
}

.sq[aria-disabled="true"] {
  cursor: default;
}

.sq.is-movable > .piece {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55), 0 2px 3px rgba(0, 0, 0, 0.35);
}

.sq.is-selected {
  box-shadow: inset 0 0 0 4px var(--brass);
}

.sq.is-target::after {
  content: "";
  position: absolute;
  width: 30%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(46, 139, 110, 0.85);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.sq.is-target.has-piece::after {
  width: 86%;
  background: none;
  box-shadow: inset 0 0 0 4px rgba(46, 139, 110, 0.9);
}

.sq.is-last-square {
  box-shadow: inset 0 0 0 999px rgba(228, 87, 46, 0.16);
}

@media (hover: hover) {
  .sq.is-target:hover::after {
    background: rgba(46, 139, 110, 1);
  }
}

/* ---------- Four in a Row ---------- */

.rack-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(4px, 1vw, 8px);
  aspect-ratio: 7 / 6.1;
  padding: clamp(8px, 1.6vw, 14px);
  border-radius: 14px;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.12), transparent 40%),
    #2459b8;
  box-shadow: var(--shadow-board);
}

.slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #12306b;
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.slot > .piece {
  width: 88%;
}

.slot.is-last > .piece {
  animation: drop 420ms cubic-bezier(0.3, 0, 0.6, 1) both;
}

@keyframes drop {
  0% { transform: translateY(calc(var(--drop, 6) * -115%)); }
  70% { transform: translateY(0); }
  85% { transform: translateY(-8%); }
  100% { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .slot.is-last > .piece {
    animation: none;
  }
}

.rack-board.is-live .slot.col-hover {
  background: #1a3f86;
}

.slot[aria-disabled="true"] {
  cursor: default;
}

/* ---------- Dots and Boxes ---------- */

.dots {
  --n: 4;
  display: grid;
  grid-template-columns: repeat(var(--n), 14px 1fr) 14px;
  grid-template-rows: repeat(var(--n), 14px 1fr) 14px;
  aspect-ratio: 1;
  padding: 18px;
  border-radius: 8px;
  background:
    linear-gradient(rgba(64, 120, 192, 0.12) 1px, transparent 1px) 0 0 / 100% 22px,
    #fbf8f0;
  box-shadow: var(--shadow-board);
}

.dots .dot {
  z-index: 2;
  place-self: center;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
}

.edge {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.edge::before {
  content: "";
  position: absolute;
  border-radius: 3px;
  background: transparent;
  transition: background-color 120ms ease;
}

.edge.h::before {
  inset: calc(50% - 3px) -2px;
}

.edge.v::before {
  inset: -2px calc(50% - 3px);
}

@media (hover: hover) {
  .dots.is-live .edge:not([aria-disabled="true"]):hover::before {
    background: rgba(34, 32, 27, 0.25);
  }
}

.edge.by-p1::before {
  background: var(--p1-flat);
}

.edge.by-p2::before {
  background: var(--p2-flat);
}

.edge.is-last::before {
  box-shadow: 0 0 0 3px rgba(228, 87, 46, 0.55);
}

.edge[aria-disabled="true"] {
  cursor: default;
}

.box {
  display: grid;
  place-items: center;
  margin: 3px;
  border-radius: 4px;
  color: #fff;
  font-family: var(--display);
  font-size: clamp(1rem, 3vw, 1.5rem);
}

.box.p1 {
  background: color-mix(in oklab, var(--p1-flat) 78%, white);
}

.box.p2 {
  background: color-mix(in oklab, var(--p2-flat) 78%, white);
}

.box.is-last {
  animation: place 300ms ease both;
}

/* ---------- Hex ---------- */

.hexes {
  --n: 7;
  padding: 4%;
  border-radius: 10px;
  background: var(--paper-raised);
  box-shadow: var(--shadow-board);
}

.hex-grid {
  --w: calc(100% / (var(--n) * 1.5 - 0.5));
}

.hex-row {
  display: flex;
  margin-top: calc(var(--w) * -0.2887);
  margin-left: calc(var(--row) * var(--w) * 0.5);
}

.hex-row:first-child {
  margin-top: 0;
}

.hex {
  position: relative;
  flex: none;
  width: var(--w);
  aspect-ratio: 0.866;
  padding: 0;
  border: 0;
  background: #d8cdb5;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  cursor: pointer;
}

.hex::before {
  content: "";
  position: absolute;
  inset: 3.5%;
  background: #f1e9d6;
  clip-path: inherit;
}

.hex.p1::before {
  background: var(--p1-flat);
}

.hex.p2::before {
  background: var(--p2-flat);
}

.hex.edge-top::before,
.hex.edge-bottom::before,
.hex.edge-left::before,
.hex.edge-right::before {
  inset: 9%;
}

.hex.edge-top,
.hex.edge-bottom {
  background: var(--p1-flat);
}

.hex.edge-left,
.hex.edge-right {
  background: var(--p2-flat);
}

.hex.edge-top.edge-left,
.hex.edge-bottom.edge-right,
.hex.edge-top.edge-right,
.hex.edge-bottom.edge-left {
  background: linear-gradient(90deg, var(--p2-flat), var(--p1-flat));
}

@media (hover: hover) {
  .hexes.is-live .hex:not([aria-disabled="true"]):hover::before {
    background: var(--you-flat);
    opacity: 0.5;
  }
}

.hex.is-last::after {
  content: "";
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px var(--last);
}

.hex.is-win::before {
  filter: brightness(1.25) saturate(1.2);
}

.hex.is-win {
  background: var(--win);
}

.hex[aria-disabled="true"] {
  cursor: default;
}

/* ---------- Mancala ---------- */

.mancala {
  display: grid;
  grid-template-columns: 1.15fr repeat(6, 1fr) 1.15fr;
  grid-template-rows: auto auto auto auto;
  align-items: center;
  gap: clamp(4px, 1.2vw, 10px);
  padding: clamp(10px, 2vw, 18px) clamp(14px, 3vw, 28px);
  border-radius: 999px / 42%;
  background:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.16), transparent 45%),
    #b9814a;
  box-shadow: var(--shadow-board), inset 0 0 0 3px #8a5a2c;
}

.mancala .side-label {
  grid-column: 2 / span 6;
  color: #3b2410;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
}

.mancala .side-label.top {
  grid-row: 1;
}

.mancala .side-label.bottom {
  grid-row: 4;
}

.pit,
.store {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fdf3df;
  background: radial-gradient(circle at 50% 35%, #6e4420, #8a5a2c 70%);
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45);
  font-family: var(--display);
  font-size: clamp(1.1rem, 2.6vw, 1.7rem);
}

.pit {
  aspect-ratio: 1;
}

.store {
  grid-row: 2 / span 2;
  align-self: stretch;
  border-radius: 999px;
}

.store .owner {
  position: absolute;
  bottom: 10%;
  font-family: var(--font);
  font-size: 0.6875rem;
  font-weight: 700;
  opacity: 0.85;
}

.pit:not([aria-disabled="true"]) {
  cursor: pointer;
}

.pit.is-mine:not([aria-disabled="true"]) {
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(255, 233, 180, 0.6);
}

@media (hover: hover) {
  .pit.is-mine:not([aria-disabled="true"]):hover {
    box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 3px var(--win);
  }
}

.pit.is-source {
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 3px var(--last);
}

.pit.is-sown,
.store.is-sown {
  color: var(--win);
}

/* ---------- Nine Men's Morris ---------- */

.morris {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  background: #f1e6cc;
  box-shadow: var(--shadow-board);
}

.morris svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.node {
  position: absolute;
  display: grid;
  place-items: center;
  width: 10%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  transform: translate(-50%, -50%);
  cursor: pointer;
}

.node::before {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: #6f6659;
}

.node > .piece {
  z-index: 1;
  width: 100%;
}

.node.is-target::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: rgba(46, 139, 110, 0.85);
}

.node.is-selected > .piece {
  box-shadow: 0 0 0 4px var(--brass), 0 2px 3px rgba(0, 0, 0, 0.35);
}

.node.is-removable > .piece {
  box-shadow: 0 0 0 4px rgba(184, 67, 47, 0.85);
}

.node[aria-disabled="true"] {
  cursor: default;
}

/* ---------- Responsive ---------- */

@media (max-width: 1000px) {
  .match {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .lobby-notes {
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
  }
}

@media (max-width: 680px) {
  .match {
    padding-top: 12px;
  }

  .side {
    grid-template-columns: minmax(0, 1fr);
  }

  .players {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .versus {
    display: none;
  }

  .player {
    min-height: 48px;
    padding: 6px 10px 6px 8px;
    gap: 8px;
  }

  .player .swatch {
    width: 22px;
    height: 22px;
  }

  .player .count {
    font-size: 1.35rem;
  }

  .stage {
    margin-inline: calc(var(--gh-gutter) * -1 + 6px);
    padding: 8px;
    border-radius: 12px;
  }

  .board-fit {
    --fit: 100%;
  }

  .dots {
    padding: 12px;
  }

  .lobby a {
    grid-template-columns: 60px minmax(0, 1fr);
    gap: 14px;
  }

  .lobby svg {
    width: 60px;
    height: 60px;
  }
}

/* ---------- Night hangar frame ----------
   With <html data-gh-scheme="night"> the card table stands under a floodlight in the dark
   hangar: the felt becomes a table with a wooden rim instead of covering the whole page. */
@media screen {
  :root[data-gh-scheme="night"] body {
    background:
      radial-gradient(ellipse 70% 40% at 50% 0%, rgba(255, 241, 214, 0.07), transparent 70%),
      var(--gh-night);
  }

  :root[data-gh-scheme="night"] .table {
    position: relative;
    z-index: 1;
    width: min(1240px, 100% - 2 * var(--gh-gutter) - 24px);
    margin-top: clamp(26px, 3.4vw, 48px);
    padding: clamp(16px, 2.6vw, 36px);
    border-radius: 26px;
    background:
      radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.1), transparent 60%),
      radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.35), transparent 60%),
      var(--felt);
    box-shadow:
      inset 0 0 0 1px rgba(255, 255, 255, 0.06),
      inset 0 0 70px rgba(0, 0, 0, 0.35),
      0 0 0 10px #5b3a1e,
      0 0 0 11px #2a1a0c,
      0 0 0 12px rgba(255, 190, 11, 0.28),
      0 60px 120px -40px rgba(0, 0, 0, 0.95),
      0 0 160px -50px rgba(255, 190, 11, 0.3);
  }

  /* A brass nameplate strip along the table's top edge. */
  :root[data-gh-scheme="night"] .table::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -11px;
    width: min(220px, 40%);
    height: 6px;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(90deg, #8a6420, #f3c968, #8a6420);
    transform: translateX(-50%);
    box-shadow: 0 0 14px rgba(255, 196, 80, 0.5);
  }

  @media (max-width: 560px) {
    :root[data-gh-scheme="night"] .table {
      width: calc(100% - 28px);
      border-radius: 18px;
      box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.06),
        inset 0 0 50px rgba(0, 0, 0, 0.35),
        0 0 0 6px #5b3a1e,
        0 0 0 7px #2a1a0c,
        0 40px 80px -30px rgba(0, 0, 0, 0.95);
    }
  }
}
