:root {
  color-scheme: light dark;
  /* base surfaces + accent align to the gloam design language (light theme) */
  --fg: #1f2328;
  --bg: #ffffff;
  --panel: #f6f8fa;
  --panel-2: #eef1f5;
  --border: #d8dee4;
  --accent: #7c3aed;
  --accent-2: #6d28d9;
  --muted: #59636e;
  --sq-light: #eef0e4;
  --sq-dark: #7f9560;
  --sq-select: #f6f078;
  --sq-target: rgba(30, 30, 30, 0.25);
  --sq-last: rgba(246, 200, 90, 0.55);
}
@media (prefers-color-scheme: dark) {
  :root {
    /* gloam dark theme */
    --fg: #e6edf3; --bg: #0d1117; --panel: #161b22; --panel-2: #1c2230;
    --border: #2a3038; --muted: #9aa7b4;
    --accent: #a371f7; --accent-2: #bd93ff;
    --sq-light: #a8a495; --sq-dark: #5c7047;
  }
}

* { box-sizing: border-box; }

/* Touch polish: kill the ~300ms tap delay and double-tap-zoom on interactive
   elements, drop the grey tap-flash, and keep long-press from selecting board
   text. Applied broadly so every game's cells/pieces feel native on a phone. */
body { -webkit-tap-highlight-color: transparent; }
button,
.board, .sq,
.bg-board, .bg-point, .bg-checker,
.c4-board, .c4-col, .c4-cell,
.ck-board, .ck-cell,
.rv-board, .rv-cell,
.gm-board, .gm-cell,
.gp-board, .gp-cell,
.hx-board, .hx-cell,
.dots-board, .dots-edge,
.go-board, .go-cell,
.xq-board, .xq-cell,
.gin-board, .gin-card,
.bs-board, .bs-cell,
.game-card, .picker-card {
  touch-action: manipulation;
}
.board, .bg-board, .c4-board, .ck-board, .rv-board, .gm-board, .gp-board,
.hx-board, .dots-board, .go-board, .xq-board, .bs-board {
  -webkit-user-select: none;
  user-select: none;
}

/* Accessibility: a visible keyboard-focus ring. Board cells, .diff-btn and gin
   cards use `all: unset`, which strips the UA outline, so re-add it explicitly.
   Board cells get an inset high-contrast ring so it shows on small squares. */
:focus-visible {
  outline: 2px solid var(--accent, #7c5cff);
  outline-offset: 2px;
}
.board :focus-visible, .bg-board :focus-visible, .c4-board :focus-visible,
.ck-board :focus-visible, .rv-board :focus-visible, .gm-board :focus-visible,
.gp-board :focus-visible, .hx-board :focus-visible, .dots-board :focus-visible,
.go-board :focus-visible, .xq-board :focus-visible, .bs-board :focus-visible,
.gin-board :focus-visible, .diff-btn:focus-visible {
  outline: 3px solid #f6f078;
  outline-offset: -2px;
  z-index: 3;
}

/* Screen-reader-only: present to assistive tech, invisible on screen. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  min-height: 100vh;
  display: grid;
  /* Bound the single column to the viewport (min 0 so content can shrink);
     without this, justify-items:center lets the column grow to max-content and
     wide views overflow horizontally on narrow screens. */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
}

.view { text-align: center; padding: 2rem; width: 100%; max-width: 60rem; }
.hidden { display: none !important; }

/* The table view anchors to the top of the page: the two game panes have
   different heights, and vertical centering would make the layout jump when
   switching tabs. */
#view-table { align-self: start; }

h1 { font-size: 3rem; margin: 0 0 0.5rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 0.5rem; }
.tagline { color: var(--muted); max-width: 34rem; margin-inline: auto; }
.note { font-size: 0.85rem; color: var(--muted); }

button {
  font: inherit;
  padding: 0.7rem 1.4rem;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--accent); }

input[type="text"] {
  font: inherit;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--muted);
  border-radius: 0.5rem;
  background: var(--panel);
  color: var(--fg);
  min-width: 0;
}

/* ---- home + lobby: gloam-styled entry screens ---- */

/* A soft purple glow sits behind the entry views. It's a fixed layer, but
   hidden views are display:none, so it only shows on home/lobby. */
#view-home::before, #view-lobby::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(58rem 42rem at 80% 6%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 60%),
    radial-gradient(46rem 34rem at 6% 96%, color-mix(in srgb, var(--accent-2) 15%, transparent), transparent 62%);
}

/* home */
#view-home { text-align: left; max-width: 66rem; }
.home-hero {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 3rem;
  align-items: center;
}
/* let both tracks shrink below their content so text wraps and the card
   never forces horizontal scroll on narrow screens */
.home-hero > * { min-width: 0; }

.brand-lockup { display: inline-flex; align-items: center; gap: 0.6rem; }
.brand-name { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }

.eyebrow {
  margin: 1.5rem 0 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
}
.home-lead h1 {
  font-size: clamp(2.4rem, 6vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0.5rem 0 0;
}
.home-lead .grad {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.home-lead .tagline {
  margin: 1.1rem 0 0;
  max-width: 32rem;
  font-size: 1.02rem;
  line-height: 1.55;
}

.trust {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.trust li {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.84rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
}
.trust-ico { font-size: 1rem; line-height: 1; }

/* action card */
.home-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.28);
}
.field { display: flex; flex-direction: column; gap: 0.35rem; text-align: left; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.field-label .opt { color: var(--muted); font-weight: 400; }
.field input { width: 100%; }

.home-card #btn-create {
  width: 100%;
  padding: 0.85rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 600;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.or-divider::before, .or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row { display: flex; gap: 0.5rem; }
.join-row #join-phrase { flex: 1; }

.home-card .note { text-align: left; margin: 0; min-height: 1.2em; }

/* solo hot-seat */
.solo-row { display: flex; gap: 0.5rem; }
.solo-row button { flex: 1; }
.difficulty { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.6rem; }
.difficulty-label { font-size: 0.85rem; color: var(--muted); margin-right: 0.1rem; }
.diff-btn {
  all: unset;
  cursor: pointer;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.diff-btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }
.solo-hint { font-size: 0.8rem; color: var(--muted); text-align: center; margin: 0.35rem 0 0; }
.solo-banner {
  display: none;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
  align-self: center;
}
#view-table.solo .solo-banner { display: inline; }
#view-table.solo .side-pane { display: none; }
#view-table.solo .table-grid { grid-template-columns: minmax(0, 1fr); }

/* invite banner (shown when arriving via a share link) */
.invite-banner {
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  border: 1px solid var(--accent);
  border-radius: 0.75rem;
  padding: 0.9rem 1.1rem;
  text-align: left;
}
.invite-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.invite-phrase {
  font-family: ui-monospace, monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 0.25rem;
  word-break: break-word;
}

/* invited mode: a single focused card — lead with Join, hide the manual
   phrase box + marketing lead, demote "Start a table" to a quiet escape hatch. */
#view-home.invited .home-hero { grid-template-columns: 1fr; max-width: 26rem; margin-inline: auto; }
#view-home.invited .home-lead { display: none; }
/* The invite banner + big Join replace the manual "join a friend" row. */
#view-home.invited #join-divider, #view-home.invited #join-phrase { display: none; }
#view-home.invited .invite-banner { order: 0; }
#view-home.invited .field { order: 1; }
#view-home.invited .join-row { order: 2; }
#view-home.invited #btn-create { order: 3; }
#view-home.invited .home-card .note { order: 4; }
/* Solo alternatives sit below the join, not above it. */
#view-home.invited #solo-divider { order: 5; }
#view-home.invited .difficulty { order: 6; }
#view-home.invited .solo-row { order: 7; }
#view-home.invited .solo-hint { order: 8; }
#view-home.invited #btn-join {
  width: 100%;
  padding: 0.85rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 600;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}
#view-home.invited #btn-create {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.3rem;
}
#view-home.invited #btn-create:hover { color: var(--accent); }

@media (max-width: 820px) {
  .home-hero { grid-template-columns: 1fr; gap: 2rem; }
  .home-card { width: 100%; max-width: 30rem; }
  .home-lead .tagline { max-width: none; }
}
@media (max-width: 560px) {
  .view { padding: 1.5rem 1.15rem; }
}

/* lobby */
.lobby-card {
  max-width: 46rem;
  margin-inline: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.75rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.28);
  text-align: left;
}
.lobby-head h2 { margin: 0; }
.lobby-head .tagline { margin: 0.5rem 0 0; max-width: none; }
.lobby-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.75rem;
  align-items: center;
  margin-top: 1.5rem;
}
.lobby-share { min-width: 0; }
.phrase {
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  font-family: ui-monospace, monospace;
  color: var(--accent);
  margin: 0 0 1rem;
  word-break: break-word;
}
.share-row { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.share-row input { flex: 1; min-width: 0; }
.lobby-share .note { margin: 0; }
.lobby-qr-wrap { display: grid; place-items: center; }
#lobby-qr { border-radius: 0.75rem; background: #fff; padding: 0.5rem; width: 11rem; height: 11rem; }

@media (max-width: 640px) {
  .lobby-body { grid-template-columns: 1fr; }
  .lobby-qr-wrap { justify-self: start; }
}

/* table */
.table-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 1.25rem;
  text-align: left;
  align-items: start;
}
@media (max-width: 760px) {
  .table-grid { grid-template-columns: 1fr; }
}

.status { font-weight: 600; margin-bottom: 0.6rem; min-height: 1.4em; }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  width: min(100%, 34rem);
  border-radius: 0.5rem;
  overflow: hidden;
  border: 2px solid var(--sq-dark);
  user-select: none;
}
.sq {
  all: unset;
  display: grid;
  place-items: center;
  font-size: clamp(1.4rem, 5.5vmin, 2.6rem);
  cursor: pointer;
  aspect-ratio: 1;
  line-height: 1;
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last-move { background-color: var(--sq-last); }
.sq.selected { outline: 3px solid var(--sq-select); outline-offset: -3px; }
.sq.target::after {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--sq-target);
}
.sq.white-piece { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.55); }
.sq.black-piece { color: #111; text-shadow: 0 1px 2px rgba(255,255,255,0.25); }

.game-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; align-items: center; }

/* game picker */
.game-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.8rem;
}
.game-card {
  background: var(--panel);
  border-radius: 0.75rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
  border: 1px solid transparent;
}
.game-card.clickable { cursor: pointer; }
.game-card.clickable:hover { border-color: var(--accent); }
.game-title { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 0.5rem; }
.game-icon { font-size: 1.9rem; line-height: 1; }
.game-badge { font-size: 0.8rem; color: var(--muted); }
.game-badge.live { color: var(--accent); font-weight: 600; }
.game-matchup { font-size: 0.78rem; color: var(--muted); }
.start-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
}
button.back { margin-bottom: 0.7rem; }

/* backgammon board */
.bg-board {
  width: min(100%, 40rem);
  border: 2px solid var(--sq-dark);
  border-radius: 0.5rem;
  background: var(--sq-light);
  padding: 0.4rem;
  user-select: none;
}
.bg-row { display: grid; grid-template-columns: repeat(6, 1fr) 0.7fr repeat(6, 1fr); gap: 2px; }
.bg-point, .bg-bar {
  all: unset;
  position: relative;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 1px;
  min-height: 7.5rem;
  cursor: pointer;
  padding: 2px;
  box-sizing: border-box;
}
.bg-row.bottom .bg-point, .bg-row.bottom .bg-bar {
  flex-direction: column-reverse;
  align-items: flex-start;
}
/* The point triangle is a pseudo-element behind the checkers — clipping the
   cell itself would clip the round checkers into triangles too. */
.bg-point::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--sq-dark);
  clip-path: polygon(0 0, 100% 0, 50% 92%);
}
.bg-row.bottom .bg-point::before { clip-path: polygon(50% 8%, 100% 100%, 0 100%); }
.bg-point.even::before { background: var(--accent); opacity: 0.92; }
.bg-bar { background: rgba(0,0,0,0.25); border-radius: 3px; align-items: center; }
.bg-point.source, .bg-bar.source { outline: 3px solid var(--sq-select); outline-offset: -3px; }
.bg-point.target, .bg-bar.target { outline: 3px dashed #fff; outline-offset: -3px; }
.checker {
  width: 1.5rem; height: 1.5rem;
  border-radius: 50%;
  align-self: center;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,0.4);
  position: relative; /* sit above the triangle pseudo-element */
  z-index: 1;
}
.checker.w { background: #f2f0e8; }
.checker.b { background: #2a2a33; border-color: rgba(255,255,255,0.3); }
.count {
  align-self: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.55);
  border-radius: 0.5rem;
  padding: 0 0.3rem;
  position: relative;
  z-index: 1;
}
.pt-label {
  position: absolute;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: rgba(255,255,255,0.6);
  z-index: 1;
}
.bg-row.bottom .pt-label { bottom: auto; top: 0; }
.bg-trays { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.4rem; }
.bg-tray {
  all: unset;
  cursor: pointer;
  padding: 0.3rem 0.7rem;
  border-radius: 0.4rem;
  background: rgba(0,0,0,0.25);
  color: #fff;
  font-size: 0.85rem;
}
.bg-tray.target { outline: 3px dashed #fff; outline-offset: -3px; }
.dice { font-size: 2rem; line-height: 1; min-width: 4.5rem; }

/* connect four */
.c4-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  width: min(100%, 26rem);
  background: var(--accent);
  padding: 8px;
  border-radius: 0.75rem;
}
.c4-cell {
  all: unset;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--bg);
  cursor: pointer;
  box-sizing: border-box;
}
.c4-cell.red { background: #e04343; }
.c4-cell.yellow { background: #f0c93c; }
.c4-cell.win { outline: 3px solid #fff; outline-offset: -3px; }

/* checkers */
.ck-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(100%, 30rem);
  aspect-ratio: 1;
  border: 2px solid var(--sq-dark);
  border-radius: 0.5rem;
  overflow: hidden;
}
.ck-cell { all: unset; display: grid; place-items: center; aspect-ratio: 1; }
.ck-cell.light { background: var(--sq-light); }
.ck-cell.dark { background: var(--sq-dark); cursor: pointer; }
.ck-cell.selected { outline: 3px solid var(--sq-select); outline-offset: -3px; }
.ck-cell.source { outline: 3px solid rgba(255,255,255,0.55); outline-offset: -3px; }
.ck-cell.target::after {
  content: "";
  width: 26%; height: 26%;
  border-radius: 50%;
  background: var(--sq-target);
  position: absolute;
}
.ck-cell { position: relative; }
.ck-piece {
  width: 70%; height: 70%;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.1rem;
  border: 2px solid rgba(0,0,0,0.4);
}
.ck-piece.p1 { background: #a03030; color: #f8d8d8; }
.ck-piece.p2 { background: #f2ead8; color: #6b5b2a; border-color: rgba(0,0,0,0.25); }

/* reversi */
.rv-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  width: min(100%, 30rem);
  aspect-ratio: 1;
  background: #1d6b3c;
  padding: 4px;
  border-radius: 0.5rem;
}
.rv-cell {
  all: unset;
  position: relative;
  display: grid;
  place-items: center;
  background: #2a8a4f;
  aspect-ratio: 1;
}
.rv-cell.legal { cursor: pointer; }
.rv-cell.legal::after {
  content: "";
  width: 24%; height: 24%;
  border-radius: 50%;
  background: rgba(0,0,0,0.35);
}
.rv-cell.last { outline: 2px solid #f6f078; outline-offset: -2px; }
.rv-disc {
  width: 78%; height: 78%;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.35);
}
.rv-disc.black { background: #17171f; }
.rv-disc.white { background: #f4f2ea; }

/* gomoku — a 15×15 wooden board; the gap shows through as grid lines */
.gm-board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 1px;
  width: min(100%, 32rem);
  aspect-ratio: 1;
  background: #b07a3c;
  padding: 5px;
  border-radius: 0.4rem;
  margin: 0 auto;
}
.gm-cell {
  all: unset;
  position: relative;
  display: grid;
  place-items: center;
  background: #d9a441;
  aspect-ratio: 1;
}
.gm-cell.open { cursor: pointer; }
.gm-cell.open:hover::after {
  content: "";
  width: 62%; height: 62%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
}
.gm-cell.last { outline: 2px solid #f6f078; outline-offset: -1px; z-index: 1; }
.gm-cell.win { background: #f0c93c; }
.gm-stone {
  width: 84%; height: 84%;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}
.gm-stone.black { background: radial-gradient(circle at 35% 30%, #565660, #16161c 72%); }
.gm-stone.white { background: radial-gradient(circle at 35% 30%, #ffffff, #d6d2c6 78%); }

/* gomoku party — a 19×19 board shared by 2–4 colored players */
.gp-board {
  display: grid;
  grid-template-columns: repeat(19, 1fr);
  gap: 1px;
  width: min(100%, 34rem);
  aspect-ratio: 1;
  background: #b07a3c;
  padding: 5px;
  border-radius: 0.4rem;
  margin: 0 auto;
}
.gp-cell {
  all: unset;
  position: relative;
  display: grid;
  place-items: center;
  background: #d9a441;
  aspect-ratio: 1;
}
.gp-cell.open { cursor: pointer; }
.gp-cell.open:hover::after {
  content: "";
  width: 64%; height: 64%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
}
.gp-cell.last { outline: 2px solid #f6f078; outline-offset: -1px; z-index: 1; }
.gp-cell.win { background: #f0c93c; }
.gp-stone {
  width: 84%; height: 84%;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
  box-shadow: inset -1px -1px 2px rgba(0, 0, 0, 0.35), inset 1px 1px 2px rgba(255, 255, 255, 0.35);
}
.gp-players {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  margin: 0.3rem 0 0.6rem;
}
.gp-player {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.9rem;
}
.gp-player.on-turn {
  border-color: var(--accent, #7c5cff);
  background: color-mix(in srgb, var(--accent, #7c5cff) 16%, transparent);
}
.gp-player.gone { opacity: 0.45; text-decoration: line-through; }
.gp-dot {
  width: 0.8rem; height: 0.8rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  flex: none;
}
.gp-player.gp-empty {
  opacity: 0.55;
  border: 1px dashed var(--border, #333);
  font-style: italic;
}
/* gomoku party lobby: take-a-seat controls */
.gp-lobby {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem;
  margin: 0.4rem 0;
  border: 1px solid var(--border, #333);
  border-radius: 12px;
  background: var(--panel-2, #16161c);
}
.gp-lobby-btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border, #333);
  background: var(--panel, #1c1c24);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.gp-lobby-btn.primary {
  border-color: var(--accent, #7c5cff);
  background: color-mix(in srgb, var(--accent, #7c5cff) 24%, transparent);
  font-weight: 600;
}
.gp-lobby-btn:hover { border-color: var(--accent, #7c5cff); }
.gp-note { opacity: 0.75; font-size: 0.92rem; }
.gp-bot-choose { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.gp-bot-choose .start-btn { min-width: 2.2rem; }

/* hex — an 11×11 rhombus of hexagons; each row is sheared right by half a cell */
.hx-board {
  --hx-cell: clamp(1.1rem, 5.4vw, 2rem);
  overflow-x: auto;
  padding: 0.5rem 0.4rem;
  background: #2a2530;
  border-radius: 0.4rem;
}
.hx-row { display: flex; gap: 2px; margin-bottom: 2px; }
.hx-cell {
  all: unset;
  flex: 0 0 auto;
  width: var(--hx-cell); height: var(--hx-cell);
  display: grid; place-items: center;
  background: #d9c9a4;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}
.hx-cell.open { cursor: pointer; }
.hx-cell.open:hover { background: #e9dcbd; }
.hx-cell.last { background: #f6f078; }
.hx-cell.win { background: #f0c93c; }
.hx-stone {
  width: 68%; height: 68%;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}
.hx-stone.red { background: radial-gradient(circle at 35% 30%, #ff6b6b, #b01e2e 75%); }
.hx-stone.blue { background: radial-gradient(circle at 35% 30%, #6ba8ff, #1e46b0 75%); }

/* dots & boxes — 6×6 dots with clickable edge segments interleaved */
.dots-board {
  --dot: 12px;
  display: grid;
  grid-template-columns: repeat(5, var(--dot) 1fr) var(--dot);
  grid-template-rows: repeat(5, var(--dot) 1fr) var(--dot);
  width: min(100%, 30rem);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 8px;
  background: #1b1b24;
  border-radius: 0.5rem;
  box-sizing: border-box;
}
.dots-dot { width: var(--dot); height: var(--dot); border-radius: 50%; background: #8a8a9c; place-self: center; }
.dots-edge { all: unset; place-self: stretch; border-radius: 3px; background: transparent; }
.dots-edge.live { cursor: pointer; }
.dots-edge.h { margin: calc(var(--dot) * 0.3) 0; }
.dots-edge.v { margin: 0 calc(var(--dot) * 0.3); }
.dots-edge.live:hover { background: rgba(124, 92, 255, 0.4); }
.dots-edge.drawn { background: #d8d8e4; }
.dots-edge.last { background: #f6f078; }
.dots-box { place-self: stretch; display: grid; place-items: center; font-size: 0.8rem; line-height: 1; margin: 1px; }
.dots-box.p1 { background: rgba(224, 67, 67, 0.30); }
.dots-box.p2 { background: rgba(74, 163, 255, 0.30); }

/* go / weiqi — a 9×9 wooden board; the 1px gap shows through as grid lines */
.go-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 1px;
  width: min(100%, 30rem);
  aspect-ratio: 1;
  background: #b07a3c;
  padding: 5px;
  border-radius: 0.4rem;
  margin: 0 auto;
}
.go-cell {
  all: unset;
  position: relative;
  display: grid; place-items: center;
  background: #d9a441;
  aspect-ratio: 1;
}
.go-cell.open { cursor: pointer; }
.go-cell.open:hover::after {
  content: "";
  width: 62%; height: 62%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
}
.go-cell.last { outline: 2px solid #f6f078; outline-offset: -1px; z-index: 1; }
.go-stone {
  width: 88%; height: 88%;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-sizing: border-box;
}
.go-stone.black { background: radial-gradient(circle at 35% 30%, #565660, #16161c 72%); }
.go-stone.white { background: radial-gradient(circle at 35% 30%, #ffffff, #d6d2c6 78%); }

/* xiangqi — 9×10 board, Chinese glyphs */
.xq-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 24rem);
  aspect-ratio: 9 / 10;
  background: #e7c48a;
  border: 2px solid #7a5b2e;
  border-radius: 0.4rem;
  overflow: hidden;
  margin: 0 auto;
}
.xq-cell {
  all: unset;
  position: relative;
  display: grid; place-items: center;
  aspect-ratio: 1;
  cursor: pointer;
  box-shadow: inset 0 0 0 0.5px rgba(122, 91, 46, 0.45);
}
.xq-cell.half-black { background: #e0b878; }
.xq-cell.palace { box-shadow: inset 0 0 0 1px rgba(122, 91, 46, 0.8); }
.xq-cell.source { outline: 3px solid rgba(255, 255, 255, 0.55); outline-offset: -3px; }
.xq-cell.selected { outline: 3px solid var(--sq-select); outline-offset: -3px; }
.xq-cell.last { background: rgba(246, 240, 120, 0.5); }
.xq-cell.target::after {
  content: "";
  position: absolute;
  width: 26%; height: 26%;
  border-radius: 50%;
  background: var(--sq-target);
}
.xq-piece {
  width: 82%; height: 82%;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: clamp(0.8rem, 4.5vw, 1.35rem);
  font-weight: 700;
  background: #f3e6c8;
  border: 2px solid #6b4f24;
}
.xq-piece.red { color: #b21f1f; border-color: #b21f1f; }
.xq-piece.black { color: #16161c; border-color: #16161c; }

/* gin rummy — playing cards */
.gin-scores { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 0.15rem 0 0.6rem; }
.gin-board { display: flex; flex-direction: column; gap: 0.8rem; align-items: stretch; }
.gin-opp { text-align: center; color: var(--muted); font-size: 0.85rem; }
.gin-piles { display: flex; gap: 1.2rem; justify-content: center; }
.gin-pile { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; }
.gin-pilelabel { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.gin-cards { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.gin-controls { display: flex; gap: 0.5rem; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 0.2rem; }
.gin-note { color: var(--muted); font-size: 0.85rem; text-align: center; }
.gin-btn { padding: 0.45rem 0.9rem; border-radius: 0.5rem; border: 1px solid var(--border); background: var(--panel-2); color: var(--fg); cursor: pointer; font-size: 0.9rem; }
.gin-btn:disabled { opacity: 0.45; cursor: default; }
.gin-btn:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.gin-card {
  width: clamp(1.9rem, 8vw, 2.4rem);
  aspect-ratio: 5 / 7;
  border-radius: 0.35rem;
  background: #f7f5ef;
  color: #16161c;
  border: 1px solid rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: default;
}
.gin-card.red { color: #c0392b; }
.gin-card.selected { outline: 3px solid var(--accent); outline-offset: -1px; transform: translateY(-5px); cursor: pointer; }
.gin-hand .gin-card { cursor: pointer; }
.gin-card.back {
  color: transparent; border-color: transparent;
  background: repeating-linear-gradient(45deg, #6d5be0, #6d5be0 4px, #4a3cc0 4px, #4a3cc0 8px);
}
.gin-rank { font-size: 1rem; font-weight: 700; line-height: 1.05; }
.gin-suit { font-size: 1.05rem; line-height: 1; }
.gin-verify { font-size: 0.85rem; text-align: center; margin-top: 0.4rem; }
.gin-verify.ok { color: #3fb950; }
.gin-verify.muted { color: var(--muted); }

/* battleship — stack the two grids so each keeps full width (side-by-side
   flex items with a percentage width collapse to nothing). Default stretch
   sizes each row item to the pane width; the gridwrap caps itself at 25rem. */
.bs-boards { display: flex; flex-direction: column; gap: 1.2rem; }
.bs-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.bs-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 1px;
  width: min(100%, 19rem);
  aspect-ratio: 1;
  background: rgba(20, 60, 110, 0.5);
  padding: 2px;
  border-radius: 0.4rem;
}
.bs-cell { all: unset; background: #2b5f8f; aspect-ratio: 1; position: relative; }
.bs-cell.shootable, .bs-cell.placeable { cursor: pointer; }
.bs-cell.shootable:hover, .bs-cell.placeable:hover { filter: brightness(1.3); }
.bs-cell.miss::after {
  content: "";
  position: absolute; inset: 35%;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
}
.bs-cell.ship { background: #6f7c86; }
.bs-cell.hit { background: #c04030; }
.bs-cell.hit::after {
  content: "✕";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #fff; font-size: 0.75rem;
}
.bs-cell.sunk { background: #7a1f14; }
.bs-cell.origin { outline: 2px solid var(--sq-select); outline-offset: -2px; }
.bs-ships { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.bs-ships .active { outline: 2px solid var(--sq-select); }

/* side pane */
.side-pane {
  background: var(--panel);
  border-radius: 0.75rem;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 24rem;
  max-height: 38rem;
}
.members { font-size: 0.95rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.3rem; }
.member { display: flex; align-items: center; gap: 0.4rem; }
.role-icon { font-size: 1.25rem; line-height: 1; color: var(--fg); opacity: 0.8; width: 1.4rem; text-align: center; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.chat-msg .who { color: var(--accent); font-weight: 600; }
.chat-msg.own .who { color: var(--muted); }
#chat-form { display: flex; }
#chat-input { flex: 1; }

/* ============================ polish layer ============================ */

/* board-pane header + mute toggle */
.board-pane-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.board-pane-head #btn-mute { margin-left: auto; }
.board-pane-head .back { margin-bottom: 0; }
.icon-btn {
  all: unset;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 0.4rem;
  opacity: 0.85;
}
.icon-btn:hover { opacity: 1; background: rgba(127, 127, 127, 0.15); }

/* turn glow — the board the local player must act on breathes softly */
.my-turn { animation: turn-glow 2.4s ease-in-out infinite; }
@keyframes turn-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124, 92, 255, 0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.45); }
}

/* enhanced chess pieces: a subtle disc + crisper glyph */
.sq { position: relative; }
.sq.white-piece, .sq.black-piece { font-weight: 400; }
.sq.white-piece { color: #f7f7fa; text-shadow: 0 1px 1px rgba(0,0,0,0.7), 0 0 2px rgba(0,0,0,0.5); }
.sq.black-piece { color: #14141a; text-shadow: 0 1px 1px rgba(255,255,255,0.35); }

/* chess coordinate labels (orientation-aware, set by the module) */
.coord {
  position: absolute;
  font-size: 0.5rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.7;
  pointer-events: none;
}
.coord.file { right: 2px; bottom: 1px; }
.coord.rank { left: 2px; top: 1px; }
.sq.light .coord { color: rgba(0, 0, 0, 0.55); }
.sq.dark .coord { color: rgba(255, 255, 255, 0.75); }

/* piece slide (FLIP) — the module sets the transform; this is the fallback */
.sq .slide-piece { display: inline-block; }

/* connect four: clip drops, column hover ghost, drop animation */
.c4-board { overflow: hidden; position: relative; }
.c4-cell.dropping { animation: c4-drop 0.34s cubic-bezier(0.5, 0, 0.6, 1); }
@keyframes c4-drop { from { transform: translateY(-340px); } to { transform: translateY(0); } }
.c4-cell.ghost-red { background: #e04343; opacity: 0.35; }
.c4-cell.ghost-yellow { background: #f0c93c; opacity: 0.35; }

/* reversi: flip animation + place pop */
.rv-disc.flip { animation: rv-flip 0.4s ease-in-out; }
@keyframes rv-flip { 0% { transform: scaleX(1); } 50% { transform: scaleX(0.05); } 100% { transform: scaleX(1); } }
.rv-cell.place-pop .rv-disc { animation: pop 0.3s ease-out; }

/* backgammon checker pop + dice tumble */
.checker.pop { animation: pop 0.28s ease-out; }
@keyframes pop { 0% { transform: scale(0.3); opacity: 0.2; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.dice.rolled { animation: dice-tumble 0.5s ease-out; }
@keyframes dice-tumble { 0% { transform: rotate(-18deg) scale(0.6); opacity: 0.3; } 60% { transform: rotate(8deg) scale(1.15); } 100% { transform: rotate(0) scale(1); opacity: 1; } }

/* checkers: crown pop */
.ck-piece.crowned { animation: pop 0.3s ease-out; }
.ck-cell.captured::after {
  content: "";
  position: absolute; inset: 15%;
  border-radius: 50%;
  background: rgba(200, 60, 60, 0.5);
  animation: fade-out 0.4s ease-out forwards;
}
@keyframes fade-out { to { opacity: 0; transform: scale(0.4); } }

/* battleship: coordinate gutters, placement preview, shot fx */
.bs-gridwrap {
  display: grid;
  grid-template-columns: 1.15rem 1fr;
  grid-template-rows: 1.15rem 1fr;
  gap: 2px;
  width: min(100%, 25rem);
}
.bs-coltop { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: repeat(10, 1fr); }
.bs-rowside { grid-column: 1; grid-row: 2; display: grid; grid-template-rows: repeat(10, 1fr); }
.bs-coltop span, .bs-rowside span { display: grid; place-items: center; font-size: 0.6rem; color: var(--muted); }
.bs-gridwrap .bs-grid { grid-column: 2; grid-row: 2; width: 100%; }
.bs-cell.preview { background: #4f7fae; outline: 2px solid rgba(255,255,255,0.6); outline-offset: -2px; }
.bs-cell.preview-bad { background: #9a4040; outline: 2px solid rgba(255,120,120,0.8); outline-offset: -2px; }
.bs-cell.miss.just::after { animation: bs-splash 0.45s ease-out; }
@keyframes bs-splash { 0% { transform: scale(2.4); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.bs-cell.hit.just { animation: bs-boom 0.4s ease-out; }
@keyframes bs-boom { 0% { transform: scale(1); filter: brightness(2.5); } 50% { transform: scale(1.25); } 100% { transform: scale(1); filter: brightness(1); } }
.bs-cell.sunk.just { animation: pulse-sunk 0.7s ease-out; }
@keyframes pulse-sunk { 0%, 100% { filter: brightness(1); } 40% { filter: brightness(1.9); } }

/* win banner */
#game-pane { position: relative; }
.win-banner {
  position: absolute;
  top: 2.5rem; left: 50%;
  transform: translate(-50%, -8px);
  z-index: 20;
  padding: 0.6rem 1.4rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.win-banner.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; cursor: pointer; }
.win-banner.win { background: linear-gradient(135deg, #7c5cff, #4aa3ff); }
.win-banner.lose { background: #55556a; }
.win-banner.neutral { background: #6b6b7b; }

/* confetti (rains over the viewport; skipped under reduced motion) */
.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.confetti-bit {
  position: absolute; top: -12px;
  width: 8px; height: 12px;
  border-radius: 1px;
  animation-name: confetti-fall;
  animation-timing-function: cubic-bezier(0.3, 0.6, 0.5, 1);
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  to { transform: translate(var(--drift, 0), 105vh) rotate(var(--rot, 180deg)); opacity: 0.15; }
}

@media (prefers-reduced-motion: reduce) {
  .my-turn { animation: none; box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.5); }
  .c4-cell.dropping, .rv-disc.flip, .rv-cell.place-pop .rv-disc, .checker.pop,
  .dice.rolled, .ck-piece.crowned, .ck-cell.captured::after,
  .bs-cell.miss.just::after, .bs-cell.hit.just, .bs-cell.sunk.just { animation: none; }
  .win-banner { transition: opacity 0.2s; }
}

/* version badge — faint, fixed, on every screen; brightens on hover */
.version-badge {
  position: fixed;
  bottom: 0.35rem;
  right: 0.55rem;
  z-index: 40;
  font-size: 0.68rem;
  font-family: ui-monospace, monospace;
  color: var(--muted);
  opacity: 0.45;
  text-decoration: none;
  pointer-events: auto;
}
.version-badge:hover { opacity: 0.9; }

/* author credit — prominent under the home hero, and a footer elsewhere */
.by-line {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  transition: color 0.15s ease;
}
.by-line strong { color: var(--fg); font-weight: 600; }
.by-line:hover { color: var(--accent); }
.by-line:hover strong { color: var(--accent); }
.by-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex: none;
}
/* credit + feedback sit on one centered, wrapping line */
.foot-credit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.foot-link {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  transition: color 0.15s ease;
}
.foot-link:hover { color: var(--accent); }
.foot-sep { color: var(--muted); opacity: 0.5; }

/* home: centered credit sitting below the hero */
#view-home .foot-credit { margin: 2.25rem auto 0; }
/* other views: a quiet footer with a hairline top rule */
.app-footer {
  margin-top: 2rem;
  padding: 1rem 1rem 2.4rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

/* toast */
.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 0.6rem;
  font-size: 0.9rem;
  max-width: 90vw;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

/* Reconnect banner: a calm, non-destructive strip pinned to the top while the
   session transparently re-establishes — the game view stays put underneath. */
.reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

/* Move-history / notation panel under each board. */
.moves-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.moves-head button { padding: 0.25rem 0.7rem; font-size: 0.78rem; }
.move-list {
  margin: 0.35rem 0 0;
  padding: 0.35rem 0.5rem 0.35rem 2.4rem;
  max-height: 9rem;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}
.move-list:empty { display: none; }
.move-list li { padding-left: 0.2rem; }
.move-list li::marker { color: var(--muted); }

/* "Just watch" join toggle on the home screen. */
.watch-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.5rem;
  cursor: pointer;
}
.watch-toggle input { accent-color: var(--accent); }

/* "N watching" presence chip in the board header (right cluster). */
.board-pane-head #watching {
  margin-left: auto;
  font-size: 0.82rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  white-space: nowrap;
}

.reconnect-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #fff;
  animation: reconnect-pulse 1s ease-in-out infinite;
}

@keyframes reconnect-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .reconnect-dot { animation: none; opacity: 0.8; }
}
