:root {
  --bg: #f4f1ea;
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --card: #ffffff;
  --line: #ddd8cc;
  --board: #626669;
  --hole: var(--bg);
  --p0: #41459e;
  --p1: #56bca6;
  --accent: #41459e;
  --danger: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --fg: #ececf0;
    --muted: #9a9aa3;
    --card: #1f2026;
    --line: #33343c;
    --board: #626669;
    --hole: var(--bg);
    --accent: #5a5fc4;
    --danger: #ff6b5b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.top { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.logo { color: var(--fg); text-decoration: none; font-weight: 700; display: inline-flex; gap: 6px; align-items: center; }
main { max-width: 560px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.6rem; margin: 12px 0 4px; }
h2 { font-size: 1.1rem; margin: 28px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 16px 0; display: grid; gap: 10px; }
label { font-weight: 600; font-size: .9rem; }
input {
  font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); width: 100%;
}
button, .button {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  padding: 11px 16px; border-radius: 10px; border: 0; background: var(--accent); color: #fff;
  display: inline-block;
}
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

.d { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.18); }
.p0 { background: var(--c0, var(--p0)); }
.p1 { background: var(--c1, var(--p1)); }
.logo .p0 { background: var(--p0); }
.logo .p1 { background: var(--p1); }

.label { font-weight: 600; font-size: .9rem; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 0; position: relative;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
}
.swatches.small .swatch { width: 28px; height: 28px; }
.swatch[aria-pressed="true"] { outline: 3px solid var(--fg); outline-offset: 3px; }
.swatch:disabled { opacity: .3; cursor: not-allowed; }
.swatch:disabled::after {
  content: ""; position: absolute; left: 15%; right: 15%; top: 50%; height: 2px;
  background: var(--fg); transform: rotate(-45deg);
}
.color-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }

.scores { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-top: 4px; }
.player { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; border: 2px solid transparent; min-width: 0; }
.player.right { justify-content: flex-end; }
.player.active { border-color: var(--line); background: var(--card); }
.player.offline .pname { opacity: .45; text-decoration: line-through; }
.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pscore { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 1.2rem; }
.vs { color: var(--muted); font-weight: 700; }

.status { text-align: center; font-weight: 600; min-height: 1.5em; margin: 10px 0; }

.board-wrap { width: 100%; max-width: 480px; margin: 0 auto; }
.preview { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 0 8px; height: 30px; }
.preview .ghost { border-radius: 50%; aspect-ratio: 1; width: 70%; margin: 0 auto; opacity: 0; transition: opacity .1s; }
.preview .ghost.show { opacity: .55; }
.board {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  background: var(--board); padding: 8px; border-radius: 14px; touch-action: manipulation;
}
.cell {
  aspect-ratio: 1; border-radius: 50%; background: var(--hole); position: relative;
  box-shadow: inset 0 3px 6px rgba(0,0,0,.25);
}
.board.can-play .cell { cursor: pointer; }
.cell .disc { position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0,0,0,.18); }
.cell .disc.drop { animation: drop var(--dur, .35s) cubic-bezier(.4,0,.6,1); }
@keyframes drop { from { transform: translateY(var(--from, -600%)); } to { transform: translateY(0); } }
.cell.win .disc { animation: pulse 1s ease-in-out infinite; }
.cell.win .disc::after { content: ""; position: absolute; inset: 30%; border-radius: 50%; background: rgba(255,255,255,.75); }
@keyframes pulse { 50% { transform: scale(.9); } }

.after { text-align: center; margin-top: 16px; }
.conn { text-align: center; color: var(--danger); font-weight: 600; }
.share { margin-top: 4px; }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.history li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; justify-content: space-between; gap: 8px; }
.history .res { font-weight: 700; white-space: nowrap; }
.history .win { color: #1f9d55; }
.history .loss { color: var(--danger); }
