:root {
  --bg: #f6f1e7; --card: #fffdf8; --ink: #23201b; --muted: #6f675b; --line: #e2d8c6;
  --accent: #1f6f4a; --accent-ink: #fff; --warn: #b3412e; --turn: #fff3c4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171a17; --card: #222622; --ink: #ece7dc; --muted: #a49c8e; --line: #363b35; --accent: #3fa877; --turn: #4a4220; }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); }
header#top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: #1f3a2e; color: #f3e9d2; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand img { width: 28px; height: 28px; }
#nav { display: flex; gap: 14px; align-items: center; font-size: .95rem; }
#nav a, #nav button { color: #f3e9d2; background: none; border: 0; font: inherit; cursor: pointer; text-decoration: none; padding: 4px 0; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 8px 0 14px; }
h2 { font-size: 1.15rem; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.narrow { max-width: 420px; margin: 24px auto; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
button, .btn { font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.danger { background: var(--warn); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.err { color: var(--warn); min-height: 1.3em; margin-top: 8px; }
.games { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.game { display: block; color: inherit; text-decoration: none; }
.game.turn { background: var(--turn); border-color: #d9b84a; }
.game .title { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.badge { font-size: .8rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: #fff; white-space: nowrap; }
.badge.grey { background: var(--muted); }
.people { display: flex; flex-wrap: wrap; gap: 8px; }
.person { padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); font-size: .9rem; }
.person.on::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #2fbf71; margin-right: 6px; }
.kinds { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kind { text-align: center; padding: 18px 10px; font-size: 1.05rem; }
.seat-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; margin: 8px 0; }

/* the game screen */
.play { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
@media (max-width: 760px) { .play { grid-template-columns: 1fr; } }
.board-wrap { width: 100%; max-width: min(640px, calc(100vh - 170px)); margin: 0 auto; }
.status { font-weight: 700; font-size: 1.05rem; margin-bottom: 8px; }
.status.mine { color: var(--accent); }
.players .p { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.players .p.now { font-weight: 700; }
.players .p.now::before { content: "▶ "; color: var(--accent); }
.moves { font-family: ui-monospace, monospace; font-size: .9rem; max-height: 180px; overflow: auto; line-height: 1.6; }
.chat-log { max-height: 220px; overflow: auto; font-size: .92rem; margin-bottom: 8px; }
.chat-log div { margin: 3px 0; }
.chat-log b { margin-right: 4px; }
/* checkers */
.ck-board { width: 100%; height: auto; display: block; border-radius: 6px; touch-action: manipulation; user-select: none; }
.ck-light { fill: #eadfc8; }
.ck-dark { fill: #6b4a2f; }
.ck-last { fill: none; stroke: #f5d76e; stroke-width: 6; }
.ck-shadow { fill: #0006; }
.ck-piece { stroke-width: 4; }
.ck-black { fill: #2a2a2a; stroke: #111; }
.ck-red { fill: #c0392b; stroke: #7d2016; }
.ck-ring { fill: none; stroke: #fff3; stroke-width: 3; pointer-events: none; }
.ck-can { stroke: #7cf0a8; stroke-width: 7; cursor: pointer; }
.ck-sel { stroke: #f5d76e; stroke-width: 8; }
.ck-crown { fill: #f5d76e; font-size: 40px; pointer-events: none; }
.ck-target { fill: #7cf0a8; opacity: .85; }
.ck-path { fill: #f5d76e; opacity: .9; }
/* Chinese checkers */
.cc-board { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; background: #f2e6cc; border-radius: 50%; }
@media (prefers-color-scheme: dark) { .cc-board { background: #3a3326; } }
.cc-hole { fill: #a8916a; }
.cc-marble { stroke: #0006; stroke-width: 1.5; }
.cc-can { stroke: #29c46d; stroke-width: 4.5; cursor: pointer; }
.cc-sel { stroke: #fff; stroke-width: 4.5; }
.cc-target { fill: #29c46d; stroke: #fff; stroke-width: 2.5; }
.cc-lastpath { fill: none; stroke: #fff; stroke-width: 4; stroke-dasharray: 6 6; opacity: .85; stroke-linecap: round; }
.cc-lastring { fill: none; stroke: #fff; stroke-width: 3; }
.cc-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid #0004; }
/* spades */
.sp-table { position: relative; background: radial-gradient(#2f7d4f, #1d5535); border-radius: 18px; aspect-ratio: 1 / .82; color: #fff; margin-bottom: 10px; }
.sp-seat { position: absolute; display: flex; flex-direction: column; align-items: center; font-size: .82rem; line-height: 1.25; padding: 4px 8px; border-radius: 10px; background: #0003; max-width: 30%; text-align: center; }
.sp-seat b { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.sp-seat.now { background: #f5d76e; color: #222; }
.sp-bottom { bottom: 6px; left: 50%; transform: translateX(-50%); }
.sp-top { top: 6px; left: 50%; transform: translateX(-50%); }
.sp-left { left: 6px; top: 50%; transform: translateY(-50%); }
.sp-right { right: 6px; top: 50%; transform: translateY(-50%); }
.sp-center { position: absolute; inset: 24% 31%; }
.sp-play { position: absolute; }
.sp-p0 { bottom: 0; left: 50%; transform: translateX(-50%); }
.sp-p2 { top: 0; left: 50%; transform: translateX(-50%); }
.sp-p1 { left: 0; top: 50%; transform: translateY(-50%); }
.sp-p3 { right: 0; top: 50%; transform: translateY(-50%); }
.sp-note { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; font-size: .85rem; text-shadow: 0 1px 2px #000; pointer-events: none; }
.pc { width: 46px; height: 66px; border-radius: 6px; background: #fff; color: #1a1a1a; border: 1px solid #0004; box-shadow: 0 1px 3px #0005;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: 1.05rem; line-height: 1.05; user-select: none; }
.pc span:last-child { font-size: 1.35rem; }
.pc.red { color: #c0392b; }
.pc.dim { opacity: .55; }
.pc.won { outline: 3px solid #f5d76e; }
.sp-hand { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; padding: 10px 0 4px; min-height: 80px; }
.sp-hand .pc { cursor: default; transition: transform .12s; }
.sp-hand .pc.ok { cursor: pointer; box-shadow: 0 0 0 2px #29c46d; }
.sp-hand .pc.no { opacity: .45; }
.sp-hand .pc.up { transform: translateY(-12px); box-shadow: 0 0 0 3px #f5d76e, 0 6px 10px #0005; }
.sp-hint { text-align: center; font-size: .85rem; min-height: 1.2em; }
.sp-bid { background: var(--card); border: 2px solid var(--accent); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.sp-bids { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 8px 0; }
.sp-bids button { padding: 8px 0; }
.sp-score td { padding: 6px 4px; }
@media (min-width: 761px) { .pc { width: 54px; height: 76px; font-size: 1.15rem; } }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; max-width: 90vw; z-index: 50; box-shadow: 0 4px 16px #0005; }
.link-box { word-break: break-all; font-family: ui-monospace, monospace; font-size: .85rem; padding: 8px; background: var(--bg); border-radius: 6px; border: 1px dashed var(--line); }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
