/* ---- themes ------------------------------------------------------------ */

:root {
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* A colour per seat, by where it sits: you, left, across, right. The same four as Hearts;
     Reversi uses you (bottom) and across (top). */
  --p0: #4f9ff0;
  --p1: #ee7961;
  --p2: #a98cf5;
  --p3: #38c6b4;
  --bad: #ee7961;
  /* The two sides of a disc. */
  --disc-b: radial-gradient(circle at 34% 30%, #5b5d63, #1d1e22 46%, #0b0b0d);
  --disc-w: radial-gradient(circle at 34% 30%, #ffffff, #f1eee7 46%, #cfcac0);
  --disc-edge: rgba(0, 0, 0, 0);
}

[data-theme="felt"] {
  --bg: #0b241c;
  --felt-1: #2e8262;
  --felt-2: #164c38;
  --ink: #f3f6f1;
  --muted: rgba(243, 246, 241, 0.66);
  --panel: rgba(6, 26, 19, 0.7);
  --panel-edge: rgba(255, 255, 255, 0.11);
  --sheet: #103528;
  --accent: #f4c95d;
  --accent-ink: #2b2104;
  /* The board: a frame, the squares, and the lines between them. */
  --rim: #0c2c21;
  --sq: #2b8b64;
  --line: #134a35;
}

[data-theme="midnight"] {
  --bg: #090b14;
  --felt-1: #2a3357;
  --felt-2: #12162a;
  --ink: #eef0f8;
  --muted: rgba(238, 240, 248, 0.62);
  --panel: rgba(9, 11, 22, 0.7);
  --panel-edge: rgba(255, 255, 255, 0.1);
  --sheet: #1a2038;
  --accent: #ffb454;
  --accent-ink: #2a1800;
  --rim: #0a0d1a;
  --sq: #36437a;
  --line: #1a2142;
}

[data-theme="linen"] {
  --bg: #e9e2d3;
  --felt-1: #fcf9f2;
  --felt-2: #ebe4d4;
  --ink: #26241e;
  --muted: rgba(38, 36, 30, 0.6);
  --panel: rgba(255, 255, 255, 0.88);
  --panel-edge: rgba(0, 0, 0, 0.09);
  --sheet: #fffdf8;
  --accent: #1f7a63;
  --accent-ink: #ffffff;
  --p0: #2f7fd1;
  --p1: #d9573d;
  --p2: #7b5fd6;
  --p3: #17968a;
  --bad: #d9573d;
  --rim: #b8ab8f;
  --sq: #3f9a72;
  --line: #2a7353;
  --disc-edge: rgba(0, 0, 0, 0.18);
}

/* ---- base -------------------------------------------------------------- */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.3 var(--font);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.p0 { --tc: var(--p0); }
.p1 { --tc: var(--p1); }
.p2 { --tc: var(--p2); }
.p3 { --tc: var(--p3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px; font-weight: 700; white-space: nowrap;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  border: 1px solid var(--panel-edge);
  transition: transform 0.12s, filter 0.12s, background 0.12s;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 16%, transparent); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.link { white-space: nowrap; color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }

/* ---- discs ------------------------------------------------------------- */

/* A disc, black or white, wherever one is drawn: on the board, on a seat, in the scoreboard. */
.disc, .tok {
  display: block; border-radius: 50%;
  box-shadow: 0 0 0 1px var(--disc-edge), 0 0.08em 0.16em rgba(0, 0, 0, 0.4);
}
:is(.disc, .tok).b { background: var(--disc-b); }
:is(.disc, .tok).w { background: var(--disc-w); }
/* A small one beside a name or a number. */
.tok { flex: none; width: 0.72em; height: 0.72em; font-style: normal; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.tok.w { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3); }
/* A black one keeps an edge on a dark panel. */
.tok.b { box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 38%, transparent); }

/* ---- room -------------------------------------------------------------- */

.room { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }

.bar {
  position: relative; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
}
.bar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-edge);
  font-weight: 700; white-space: nowrap;
}
.chip small { color: var(--muted); font-weight: 600; font-size: 12px; }
.chip.icon { width: 40px; padding: 0; justify-content: center; font-size: 18px; }
.chip:hover { border-color: color-mix(in srgb, var(--ink) 30%, transparent); }

/* Lives in the top bar's markup; on a wide screen it hangs just below it, over the table's corner.
   A row per player: name, discs on the board now, and games won. (The same board as Hearts.) */
.board {
  position: absolute; top: calc(100% + 12px); right: 22px; z-index: 4;
  display: grid; grid-template-columns: auto auto auto; align-items: stretch;
  border-radius: 14px; overflow: hidden; text-align: center;
  background: var(--panel); border: 1px solid var(--panel-edge);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums;
}
.board .pl { display: contents; }
.board .pl > * {
  display: grid; place-items: center; padding: 3px 11px; min-height: 32px;
  background: color-mix(in srgb, var(--tc) 30%, transparent); border-top: 1px solid var(--panel-edge);
}
.board .head > * { min-height: 0; padding: 5px 11px 4px; background: none; border-top: 0; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.board .pl > .tn { display: block; text-align: left; font-size: 13px; font-weight: 700; max-width: 14ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 26px; }
.board b { font-size: 18px; font-weight: 800; }
.board .pl > b { display: flex; align-items: center; justify-content: center; gap: 6px; }
.board .tok { font-size: 15px; }
.board .ph { font-size: 14px; font-weight: 700; }
.board:hover { border-color: color-mix(in srgb, var(--ink) 30%, transparent); }

/* The table: the other player's seat across the top, the board, your seat below it.
   The board's row is never taller than the table is wide, so on a tall phone the
   three sit together in the middle rather than the seats drifting to the edges. */
.felt {
  position: relative; margin: 0 10px; min-height: 0; border-radius: 28px;
  container-type: size;
  display: grid; gap: 10px; padding: 12px 14px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto minmax(0, calc(100cqw - 28px)) auto minmax(0, 1fr);
  grid-template-areas: "." "top" "mid" "bottom" ".";
  background: radial-gradient(ellipse 80% 70% at 50% 42%, var(--felt-1), var(--felt-2));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 0 90px rgba(0, 0, 0, 0.22),
    0 14px 40px rgba(0, 0, 0, 0.28);
}

/* Felt fibres: a seamless grey tile laid over whichever theme colour is underneath. */
.felt::before, .home::before {
  content: ""; position: absolute; inset: 0; z-index: 0; border-radius: inherit; pointer-events: none;
  background: url(/shared/felt.webp) 0 0 / 640px 320px;
  mix-blend-mode: overlay; opacity: 0.125;
}

/* ---- seats ------------------------------------------------------------- */

.zone { position: relative; z-index: 2; display: flex; justify-content: center; min-width: 0; }
.zone.pos-top { grid-area: top; }
.zone.pos-bottom { grid-area: bottom; }

.seat {
  position: relative; display: flex; align-items: center; gap: 9px; max-width: 100%;
  padding: 6px 14px 6px 6px; border-radius: 999px;
  --seat-bg: color-mix(in srgb, var(--tc) 26%, var(--panel));
  background: var(--seat-bg);
  border: 1px solid color-mix(in srgb, var(--tc) 50%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: box-shadow 0.25s, background 0.25s, transform 0.25s;
}
.seat.turn { box-shadow: 0 0 0 2px var(--accent), 0 0 24px color-mix(in srgb, var(--accent) 50%, transparent); }
.seat.won { box-shadow: 0 0 0 3px var(--accent); }
.seat.away .avatar, .seat.away .who { opacity: 0.5; }
.seat.empty { padding: 6px; gap: 6px; border-style: dashed; }
.seat.empty .link { padding: 0 10px 0 4px; }

.avatar {
  position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
  color: #fff; background: var(--tc);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.avatar > svg:not(.ring) { width: 23px; height: 23px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2)); }
.ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); transform: rotate(-90deg); pointer-events: none; }
.ring circle {
  fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: var(--from);
  animation: drain linear forwards;
}
@keyframes drain { to { stroke-dashoffset: 100; } }
/* The colour a player has this game: a disc on the corner of their picture, where the
   card games put the dealer button. */
.avatar .tok {
  position: absolute; right: -5px; bottom: -4px; z-index: 1; width: 17px; height: 17px;
  box-shadow: 0 0 0 2px var(--seat-bg);
}

.who { min-width: 0; }
.who .name { display: flex; align-items: center; gap: 7px; font-weight: 700; white-space: nowrap; }
.who .name span { overflow: hidden; text-overflow: ellipsis; max-width: 13ch; }
.who .stat { font-size: 12.5px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat.turn .stat, .stat .host { color: var(--accent); }
.seat .x { width: 24px; height: 24px; border-radius: 50%; color: var(--muted); font-size: 16px; line-height: 1; margin-right: -6px; }
.seat .x:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); color: var(--ink); }

/* When the table is waiting on you, your own seat becomes the banner. */
.seat.me.turn {
  --seat-bg: var(--accent);
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
  padding-right: 22px;
  transform: scale(1.12);
  animation: beckon 1.6s ease-in-out infinite;
}
.seat.me.turn .name { font-size: 18px; font-weight: 800; }
/* The bigger "Your turn" keeps the usual line height, so the seat doesn't grow and push the table about. */
.who .name { height: 19.5px; } /* 15px text at the page's 1.3 line height */
.seat.me.turn .name span { line-height: 1; }
.seat.me.turn .stat { color: inherit; opacity: 0.8; }
.seat.me.turn .avatar { background: var(--accent-ink); color: var(--accent); text-shadow: none; }
.seat.me.turn .ring circle { stroke: var(--accent-ink); }
@keyframes beckon {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent), 0 8px 24px rgba(0, 0, 0, 0.3); }
  50% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--accent) 0%, transparent), 0 8px 24px rgba(0, 0, 0, 0.3); }
}

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

/* As big a square as the middle of the table holds. */
.mid { grid-area: mid; position: relative; z-index: 1; container-type: size; display: grid; place-items: center; min-height: 0; }
[data-phase="lobby"] .mid { display: none; }
.field {
  --gap: max(1.5px, min(0.45cqw, 0.45cqh));
  --pad: min(2.2cqw, 2.2cqh);
  position: relative; width: min(100cqw, 100cqh); aspect-ratio: 1;
  display: grid; grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr)); gap: var(--gap);
  padding: var(--pad); border-radius: min(3cqw, 3cqh);
  background: var(--line);
  box-shadow: inset 0 0 0 var(--pad) var(--rim), 0 0 0 1px rgba(0, 0, 0, 0.18), 0 16px 34px rgba(0, 0, 0, 0.32);
}
/* The four small dots where the lines cross around the middle of the board, as on a real one. */
.field::after {
  --d: max(6px, min(1.7cqw, 1.7cqh));
  content: ""; position: absolute; inset: var(--pad); pointer-events: none; z-index: 1;
  background:
    radial-gradient(circle closest-side, var(--line) 98%, transparent) calc(25% - var(--d) / 2 + var(--gap) * 0.25) calc(25% - var(--d) / 2 + var(--gap) * 0.25) / var(--d) var(--d) no-repeat,
    radial-gradient(circle closest-side, var(--line) 98%, transparent) calc(75% + var(--d) / 2 - var(--gap) * 0.25) calc(25% - var(--d) / 2 + var(--gap) * 0.25) / var(--d) var(--d) no-repeat,
    radial-gradient(circle closest-side, var(--line) 98%, transparent) calc(25% - var(--d) / 2 + var(--gap) * 0.25) calc(75% + var(--d) / 2 - var(--gap) * 0.25) / var(--d) var(--d) no-repeat,
    radial-gradient(circle closest-side, var(--line) 98%, transparent) calc(75% + var(--d) / 2 - var(--gap) * 0.25) calc(75% + var(--d) / 2 - var(--gap) * 0.25) / var(--d) var(--d) no-repeat;
}
.sq {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
  background: var(--sq); cursor: default;
  container-type: inline-size;
}
.sq .disc { width: 82%; aspect-ratio: 1; font-size: 100cqw; }
/* The latest disc put down carries a small mark. */
.sq.last .disc::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 18%; height: 18%; border-radius: 50%;
  transform: translate(-50%, -50%); background: var(--accent); box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.25);
}
.sq .disc { position: relative; }

/* Your turn: the squares you may play show a faint ring of your colour. */
.my-turn .sq.can { cursor: pointer; }
.my-turn .sq.can::before {
  content: ""; width: 34%; aspect-ratio: 1; border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--hint) 70%, transparent);
}
[data-hints="off"] .my-turn .sq.can::before { display: none; }
.field[data-mine="B"] { --hint: #111; --ghost: var(--disc-b); }
.field[data-mine="W"] { --hint: #fff; --ghost: var(--disc-w); }
/* With a mouse, the square under it shows the disc you would put there, and the discs it would turn. */
@media (hover: hover) {
  .my-turn .sq.can:hover::before {
    width: 82%; background: var(--ghost); box-shadow: none; opacity: 0.55;
  }
  [data-hints="off"] .my-turn .sq.can:hover::before { display: block; }
  .sq .disc.would { box-shadow: 0 0 0 2px var(--accent), 0 0.08em 0.16em rgba(0, 0, 0, 0.4); }
}

/* A disc put down drops on; one that is turned over flips, nearest first. */
.disc.drop { animation: drop 0.3s cubic-bezier(0.25, 1, 0.5, 1) backwards; }
@keyframes drop { from { transform: translateY(-14%) scale(1.25); opacity: 0; } }
.disc.turn.b { animation: turn-b 0.42s ease-in-out backwards; }
.disc.turn.w { animation: turn-w 0.42s ease-in-out backwards; }
@keyframes turn-b {
  0% { transform: none; background: var(--disc-w); }
  50% { transform: translateY(-8%) scale(0.06, 1.06); }
  100% { transform: none; background: var(--disc-b); }
}
@keyframes turn-w {
  0% { transform: none; background: var(--disc-b); }
  50% { transform: translateY(-8%) scale(0.06, 1.06); }
  100% { transform: none; background: var(--disc-w); }
}
/* A square you can't play shakes. */
.sq.nope { animation: nope 0.3s; }
@keyframes nope { 25% { translate: -3px 0; } 75% { translate: 3px 0; } }

/* ---- centre of the table ---------------------------------------------- */

.center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92%, 460px); text-align: center; z-index: 3; pointer-events: none;
}
.center:empty { display: none; }
.center > * { pointer-events: auto; }
/* In the lobby the settings take the middle of the table, between the seats. */
[data-phase="lobby"] .felt { grid-template-rows: minmax(0, 1fr) auto auto auto minmax(0, 1fr); }
[data-phase="lobby"] .center { position: relative; left: auto; top: auto; transform: none; grid-area: mid; align-self: center; justify-self: center; width: min(100%, 440px); }
.panel {
  max-height: calc(100cqh - 16px); overflow-y: auto;
  padding: 20px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--panel-edge);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}
.panel h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.panel h2 code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.08em; }
.panel p { color: var(--muted); margin-top: 6px; }
.panel p .link { margin-left: 4px; }
.panel .row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.status {
  display: inline-block; max-width: 100%; padding: 9px 18px; border-radius: 22px; font-weight: 700; font-size: 15px; overflow-wrap: anywhere;
  background: var(--panel); border: 1px solid var(--panel-edge);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}

.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 9%, transparent); }
.seg button { padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--ink); color: var(--bg); }
.opts { display: grid; gap: 6px; margin-top: 14px; justify-content: center; }
.opt { display: grid; grid-template-columns: 84px auto; align-items: center; justify-items: start; gap: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---- below the table --------------------------------------------------- */

/* There is no hand to hold, so below the table is only a line for anyone watching,
   and the result once a game is over and its sheet is put away. */
.foot { display: grid; justify-items: center; padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px); }
.foot:has(> :not([hidden])) { padding-top: 10px; }
.watching { margin: 0; padding: 2px 12px; text-align: center; font-weight: 600; color: var(--muted); }
.result { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 12px; font-weight: 700; }
.result .btn { padding: 8px 16px; font-size: 14px; }

/* ---- sheets, menu, toast ---------------------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.45); animation: fade 0.2s;
}
.sheet {
  width: min(100%, 460px); max-height: 100%; overflow: hidden auto; padding: 24px; border-radius: 24px; text-align: center;
  background: var(--sheet); border: 1px solid var(--panel-edge); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  animation: rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.wide { width: min(100%, 600px); }
.sheet h2 { font-size: 24px; font-weight: 800; overflow-wrap: anywhere; }
.sheet p { color: var(--muted); margin-top: 6px; }
.sheet .row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.sheet .peek { margin-top: 14px; }
.sheet input {
  width: 100%; margin-top: 16px; padding: 13px 16px; border-radius: 14px; text-align: center; font-weight: 700; font-size: 17px;
  background: color-mix(in srgb, var(--ink) 8%, transparent); border: 1px solid var(--panel-edge); outline: none;
  -webkit-user-select: text; user-select: text;
}
.sheet input:focus { border-color: var(--accent); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

.tally { width: 100%; margin-top: 16px; border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.tally th:first-child { width: 25%; }
.tally th, .tally td { padding: 7px 6px; text-align: right; }
.tally th:first-child, .tally td:first-child { text-align: left; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tally thead th { font-size: 13px; font-weight: 700; color: var(--tc); border-bottom: 1px solid var(--panel-edge); }
.tally thead th span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally td small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.tally .sum td { border-top: 1px solid var(--panel-edge); font-weight: 700; }
.tally .total td { font-size: 20px; font-weight: 800; }
.tally .total td:first-child { font-size: 15px; }
.tally .side { display: inline-flex; align-items: center; gap: 6px; }

/* The full score sheet: current standings, then a row per game with a column per player. */
.standings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.standing {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 8px 14px 8px 12px; border-radius: 14px;
  background: color-mix(in srgb, var(--tc) 22%, transparent); text-align: left; min-width: 0;
}
.standing span { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing span small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.standing b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--tc); }
.scroll { max-height: min(46vh, 420px); overflow: auto; margin-top: 10px; }
.tally.log { margin-top: 0; }
.tally.log thead th { position: sticky; top: 0; z-index: 1; background: var(--sheet); font-size: 12px; }
.tally.log tbody td { padding: 8px 6px; border-top: 1px solid var(--panel-edge); vertical-align: top; }
.tally.log tbody tr:first-child td { border-top: 0; }
.tally.log td b { display: block; font-size: 16px; font-weight: 800; color: var(--ink); }
.tally.log td small { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tally.log td:first-child b { font-size: 13px; font-weight: 700; }
.tally.log td small .tok { display: inline-block; vertical-align: -0.05em; margin-right: 4px; }

/* How to play: a little board showing a move, then the rules. */
.rules { margin-top: 14px; text-align: left; }
.rules p { margin-top: 8px; font-size: 14px; line-height: 1.45; }
.rules b { color: var(--ink); }
.example { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.example .field { --pad: 5px; --gap: 2px; width: 150px; border-radius: 10px; grid-template: repeat(4, minmax(0, 1fr)) / repeat(4, minmax(0, 1fr)); container-type: normal; }
.example .field::after { display: none; }
.example .sq .disc { font-size: 22px; }
.example .arrow { font-size: 24px; font-weight: 800; color: var(--muted); }
.example .sq.new .disc { box-shadow: 0 0 0 2px var(--accent), 0 2px 4px rgba(0, 0, 0, 0.4); }

.menu {
  position: fixed; right: 12px; top: calc(max(10px, env(safe-area-inset-top)) + 46px); z-index: 15; width: 250px; padding: 8px;
  max-height: calc(100dvh - 70px); overflow-y: auto;
  border-radius: 18px; background: var(--sheet); border: 1px solid var(--panel-edge); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  animation: rise 0.16s;
}
.menu .item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 11px; font-weight: 600; }
.menu a.item { color: inherit; text-decoration: none; }
.menu :is(button, a).item:hover { background: color-mix(in srgb, var(--ink) 9%, transparent); }
.menu .item.static { justify-content: space-between; padding: 6px 8px 6px 12px; }
.menu .seg button { padding: 5px 8px; font-size: 12px; }
.menu .check { width: 16px; font-style: normal; font-weight: 800; color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--panel-edge); margin: 6px 4px; }
.menu .swatches { display: flex; gap: 8px; padding: 8px 12px 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 0 1px var(--panel-edge); }
.swatch.on { border-color: var(--accent); }
.swatch[data-set-theme="felt"] { background: radial-gradient(#2e8262, #164c38); }
.swatch[data-set-theme="midnight"] { background: radial-gradient(#2a3357, #12162a); }
.swatch[data-set-theme="linen"] { background: radial-gradient(#fcf9f2, #e0d7c3); }

.toast {
  position: fixed; left: 50%; top: 40%; transform: translateX(-50%); z-index: 30;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; text-align: center;
  background: var(--ink); color: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  animation: rise 0.2s;
}

/* ---- home -------------------------------------------------------------- */

.home { position: relative; isolation: isolate; height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at 50% 30%, var(--felt-1), var(--felt-2) 70%); }
.home .sheet { position: relative; z-index: 1; animation: none; }
/* Back to the list of games, in the corner above the start page. */
.home .all-games { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 14px; z-index: 2; color: inherit; text-decoration: none; }
.home .all-games span { font-size: 20px; line-height: 1; margin-top: -2px; }
.home .logo { width: 92px; margin: 0 auto; }
.home .logo svg { display: block; width: 100%; height: auto; }
.home h2 { margin-top: 10px; }
.home h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; }
.home .tag { margin-top: 2px; }
.home .btn.primary { width: 100%; margin-top: 12px; padding: 14px; font-size: 17px; }
.home .join { display: flex; gap: 8px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--panel-edge); }
.home .join input { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; }
.home .join .btn { flex: none; }
.home .join input.nope { animation: nope 0.3s; }
.home .rules-link { margin-top: 16px; }

/* Narrower than a laptop: scoreboard names get shorter so the board stays in its corner. */
@media (max-width: 900px) {
  .board .pl > .tn { max-width: 9ch; }
}

/* A window not much wider than it is tall leaves no corner beside the board for the
   scoreboard, so it joins the top bar as a strip, name and score side by side. */
@media (max-aspect-ratio: 6/5) and (min-width: 641px) {
  .board { position: static; display: flex; height: 34px; }
  .board .pl {
    display: flex; align-items: center; gap: 6px; padding: 0 10px;
    background: color-mix(in srgb, var(--tc) 30%, transparent); border-left: 1px solid var(--panel-edge);
  }
  .board .pl.head + .pl { border-left: 0; }
  .board .pl > * { display: block; min-height: 0; padding: 0; background: none; border: 0; }
  .board .pl.head, .board .pl > .ph { display: none; }
  .board .pl > .tn { max-width: 9ch; font-size: 12px; line-height: 1.2; }
  .board b { font-size: 15px; gap: 5px; }
}

/* ---- small screens ----------------------------------------------------- */

@media (max-width: 640px) {
  .chip.table small { display: none; }
  .bar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .chip.table { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; height: 46px; border-radius: 14px; line-height: 1.1; }
  .chip.table .word { font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
  .felt { margin: 0 6px; border-radius: 22px; padding: 10px 8px; gap: 10px; }

  /* The scoreboard sits in the top bar: a coloured column per player, name over score. */
  .bar .spacer { display: none; }
  .board { position: static; display: flex; flex: 1 1 0; min-width: 0; max-width: 300px; margin-left: auto; height: 46px; }
  .board .pl {
    display: grid; align-content: center; justify-items: center; gap: 2px; flex: 1 1 0; min-width: 0; padding: 0 5px;
    background: color-mix(in srgb, var(--tc) 30%, transparent); border-left: 1px solid var(--panel-edge);
  }
  .board .pl.head + .pl { border-left: 0; }
  .board .pl > * { display: block; min-height: 0; padding: 0; background: none; border: 0; }
  .board .pl.head, .board .pl > .ph { display: none; }
  .board .pl > .tn { max-width: 100%; font-size: 10.5px; line-height: 1.1; text-align: center; color: var(--muted); }
  .board b { font-size: 18px; line-height: 1; gap: 5px; }
  .panel { padding: 16px; }
  .panel .row { margin-top: 12px; }

  /* Smaller name plates. */
  .seat { gap: 7px; padding: 4px 11px 4px 4px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
  .avatar > svg:not(.ring) { width: 19px; height: 19px; }
  .avatar .tok { width: 14px; height: 14px; right: -4px; bottom: -3px; }
  .who .name { font-size: 14px; height: 18.2px; }
  .who .stat { font-size: 11.5px; }
  .seat.me.turn { padding-right: 18px; transform: scale(1.04); }
  .seat.me.turn .name { font-size: 16px; }
  .zone.pos-top .who .name span { max-width: 10ch; }

  .sheet { padding: 20px 16px; }
  .tally th, .tally td { padding: 7px 4px; }
  .tally th:first-child { width: 27%; }
  .tally .total td { font-size: 18px; }
  .standing { padding: 7px 10px; }
  .standing b { font-size: 19px; }
}

/* Short phones: tighten up so the whole table fits. */
@media (max-width: 640px) and (max-height: 700px) {
  .panel { padding: 12px 14px; border-radius: 18px; }
  .panel h2 { font-size: 19px; }
  .panel > p:first-of-type { display: none; }
  .panel .row { margin-top: 10px; }
  .opts { margin-top: 10px; gap: 4px; }
  .felt { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
}

/* ---- short windows ----------------------------------------------------- */

/* A laptop window that isn't tall: a compact scoreboard, as in the card games. */
@media (max-height: 620px) and (min-width: 641px) {
  .board .pl > * { min-height: 25px; padding: 1px 10px; }
  .board .head > * { min-height: 0; padding: 4px 10px 3px; }
  .board b { font-size: 16px; }
  .board .pl > .tn { line-height: 22px; }
  .felt { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
}

/* A phone on its side: very little height, so the seats move beside the board,
   the other player above you, and the board takes the whole height. */
@media (max-height: 480px) and (min-width: 641px) {
  .bar { padding-top: 6px; padding-bottom: 6px; }
  .chip { height: 34px; }
  .chip.icon { width: 34px; }
  .board { position: static; display: flex; height: 34px; }
  .board .pl {
    display: flex; align-items: center; gap: 6px; padding: 0 10px;
    background: color-mix(in srgb, var(--tc) 30%, transparent); border-left: 1px solid var(--panel-edge);
  }
  .board .pl.head + .pl { border-left: 0; }
  .board .pl > * { display: block; min-height: 0; padding: 0; background: none; border: 0; }
  .board .pl.head, .board .pl > .ph { display: none; }
  .board .pl > .tn { max-width: 9ch; font-size: 12px; line-height: 1.2; }
  .board b { font-size: 15px; gap: 5px; }
  .foot { padding-top: 0; padding-bottom: calc(env(safe-area-inset-bottom) + 6px); }
  .felt {
    margin: 0 8px; border-radius: 20px; padding: 8px 10px; gap: 8px 14px;
    grid-template-columns: minmax(0, 1fr) calc(100cqh - 16px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "top mid ." "bottom mid .";
  }
  [data-phase="lobby"] .felt {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .zone { justify-content: flex-end; }
  .zone.pos-top { align-items: flex-start; }
  .zone.pos-bottom { align-items: flex-end; }
  .seat { padding: 3px 10px 3px 3px; gap: 6px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
  .avatar .tok { width: 14px; height: 14px; right: -4px; bottom: -3px; }
  .who .name { font-size: 13px; height: 16.9px; }
  .who .stat { font-size: 11px; }
  .seat.me.turn { transform: scale(1.04); transform-origin: right center; }
  .panel { padding: 10px 14px; border-radius: 16px; max-height: calc(100cqh - 8px); }
  .panel h2 { font-size: 17px; }
  .panel > p:first-of-type { display: none; }
  .panel .row { margin-top: 8px; }
  .opts { margin-top: 8px; gap: 3px; }
}
