:root {
  --bg: #15181d;
  --panel: #1e2229;
  --panel-2: #272c35;
  --line: #333a45;
  --text: #e9e6df;
  --muted: #9aa1ad;
  --accent: #e0a94a;
  --accent-ink: #1b1508;
  --danger: #d9634f;
  --ok: #6fbf73;
  --felt: #ecdfc7;
  --point-a: #a97c5a;
  --point-b: #6f8f7a;
  --rail: #5b4030;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f1ea;
    --panel: #ffffff;
    --panel-2: #f0ece3;
    --line: #dcd6c8;
    --text: #23262b;
    --muted: #6a707b;
    --accent: #b9781a;
    --accent-ink: #ffffff;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 1120px; margin: 0 auto;
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 20px; letter-spacing: .02em; }
.brand-mark { width: 24px; height: 24px; vertical-align: -5px; fill: var(--accent); }
.brand-mark circle { fill: var(--bg); }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .chip input:focus-visible + span, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.big { width: 100%; font-size: 18px; padding: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Home screen */
.home { max-width: 560px; margin: 0 auto; padding: 8px 16px 40px; }
.home h1 { font-size: 30px; margin: 12px 0 4px; }
.lead { color: var(--muted); margin: 0 0 20px; }
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip > span {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 76px; min-height: 48px; padding: 6px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600;
}
.chip > span small { font-weight: 400; color: var(--muted); font-size: 12px; }
.chip input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.linkrow input, .joinrow input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit; min-height: 44px; min-width: 0;
}
/* Game */
.game { max-width: 1120px; margin: 0 auto; padding: 0 12px 24px; }
.invite {
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 auto 14px; max-width: 720px;
}
.invite h2 { margin: 0 0 2px; font-size: 20px; }
.invite p { margin: 0 0 10px; color: var(--muted); }
.linkrow { display: flex; gap: 8px; flex-wrap: wrap; }
.linkrow input { flex: 1 1 220px; }
.apps { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.invite-more {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
.qr { flex: none; width: 148px; height: 148px; border-radius: 8px; overflow: hidden; background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.invite-alt { flex: 1 1 220px; }
.invite-alt p:last-child { margin-bottom: 0; }
.coderow { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.code {
  font: 700 26px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .12em; color: var(--text); user-select: all; white-space: nowrap;
}
.warn { color: var(--accent) !important; font-size: 14px; margin: 10px 0 0 !important; }

.layout { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.boardcol { --size: min(100vw - 24px, 100dvh - 196px, 720px); width: var(--size); }
.players, .side { width: 100%; max-width: 720px; }
.side { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 900px) {
  .layout {
    display: grid; grid-template-columns: auto 320px; grid-template-rows: auto 1fr;
    grid-template-areas: "board clocks" "board side";
    justify-content: center; align-items: start; gap: 10px 20px;
  }
  .boardcol { grid-area: board; --size: min(100vw - 400px, 100dvh - 90px, 760px); }
  .players { grid-area: clocks; }
  .side { grid-area: side; }
}


/* Both players side by side: White on the left, Black on the right */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.playerbox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 0; }
.playerbox .who { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.playerbox .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playerbox .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.playerbox .dot.on { background: var(--ok); }
.playerbox .pips { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.playerbox.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.playerbox.active .who, .playerbox.active .pips { color: var(--text); }

/* The board: 14 columns (6 points, the bar, 6 points, the tray for borne-off checkers) and
   three rows (the far points, the strip with the dice, the near points). */
.board {
  --cell: calc(var(--size) / 14);
  width: var(--size); height: calc(var(--cell) * 12);
  display: grid; grid-template-columns: repeat(14, 1fr); grid-template-rows: 5fr 2fr 5fr;
  background: var(--felt); border-radius: 6px; overflow: hidden; position: relative;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
.pt { position: relative; display: flex; flex-direction: column; align-items: center; min-height: 0; }
.pt.far { grid-row: 1; }
.pt.near { grid-row: 3; flex-direction: column-reverse; }
.pt::before { content: ""; position: absolute; inset: 0 6%; background: var(--point-a); clip-path: polygon(0 0, 100% 0, 50% 100%); }
.pt.near::before { clip-path: polygon(0 100%, 100% 100%, 50% 0); }
.pt.alt::before { background: var(--point-b); }
/* the points of the last turn: a small mark at the base */
.pt.last::after {
  content: ""; position: absolute; left: 22%; right: 22%; top: 0; height: calc(var(--cell) * .14); z-index: 2;
  background: var(--accent); border-radius: 0 0 4px 4px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}
.pt.near.last::after { top: auto; bottom: 0; border-radius: 4px 4px 0 0; }
.pt.target::before, .pt.target.alt::before { background: var(--ok); filter: none; }
.pt.movable, .pt.target, .lane.movable, .tray.target { cursor: pointer; }
.ck {
  width: var(--cell); height: var(--cell); border-radius: 50%; flex: none; position: relative; z-index: 1;
  box-sizing: border-box; border: max(1px, calc(var(--cell) * .05)) solid #8a8478;
}
.ck.w { background: radial-gradient(circle at 35% 30%, #ffffff, #e4dfd2 70%); }
.ck.b { background: radial-gradient(circle at 35% 30%, #4a4744, #171615 70%); border-color: #77726a; }
/* More than five on a point: they overlap so that the stack keeps its height. */
.pt.far .ck + .ck, .lane.far .ck + .ck { margin-top: var(--lap, 0px); }
.pt.near .ck + .ck { margin-bottom: var(--lap, 0px); }
.sel .ck:last-child { box-shadow: 0 0 0 calc(var(--cell) * .09) var(--accent), 0 0 calc(var(--cell) * .4) var(--accent); }
.movable .ck:last-child { border-color: var(--accent); }

.bar, .tray { grid-row: 1 / 4; display: grid; grid-template-rows: 1fr 1fr; background: var(--rail); }
.bar { grid-column: 7; }
.tray { grid-column: 14; box-shadow: inset 2px 0 0 rgba(0, 0, 0, .25); }
.lane { display: flex; flex-direction: column; align-items: center; min-height: 0; }
/* checkers on the bar gather around the middle of the board */
.bar .lane.far { justify-content: flex-end; padding-bottom: calc(var(--cell) * 1.1); }
.bar .lane.near { padding-top: calc(var(--cell) * 1.1); }
.bar .lane.near .ck + .ck { margin-top: var(--lap, 0px); }
.tray .lane { padding: calc(var(--cell) * .12) 0; gap: 1px; }
.tray .lane.near { flex-direction: column-reverse; }
.slab { width: 78%; height: calc(var(--cell) * .28); border-radius: 2px; flex: none; }
.slab.w { background: #f3efe5; box-shadow: inset 0 0 0 1px #8a8478; }
.slab.b { background: #232120; box-shadow: inset 0 0 0 1px #77726a; }
.tray.target { box-shadow: inset 0 0 0 calc(var(--cell) * .12) var(--ok); }

/* The strip between the points: the dice of the side to move, and the buttons of the turn */
.mid { grid-row: 2; display: flex; align-items: center; justify-content: center; gap: calc(var(--cell) * .16); min-width: 0; }
.mid.left { grid-column: 1 / 7; }
.mid.right { grid-column: 8 / 14; }
.die {
  width: calc(var(--cell) * 1.3); height: calc(var(--cell) * 1.3); flex: none; border-radius: 18%;
  background: #fbfaf6; box-shadow: 0 1px 3px rgba(0, 0, 0, .45), inset 0 0 0 1px #b9b2a3;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: calc(var(--cell) * .17); box-sizing: border-box;
}
.die i { border-radius: 50%; margin: calc(var(--cell) * .035); }
.die i.on { background: #1c1b1a; }
.die.dark { background: #2a2826; box-shadow: 0 1px 3px rgba(0, 0, 0, .45), inset 0 0 0 1px #77726a; }
.die.dark i.on { background: #f3efe5; }
.die.used { opacity: .35; }
.mid .btn {
  min-height: 0; height: calc(var(--cell) * 1.5); padding: 0 calc(var(--cell) * .45); border-radius: calc(var(--cell) * .3);
  font-size: clamp(12px, calc(var(--cell) * .5), 18px); white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
.mid .btn:not(.primary) { background: var(--panel); }

.status { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-weight: 700; font-size: 17px; }
.status.turn { border-color: var(--accent); }
.status small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }
.rules { color: var(--muted); font-size: 14px; padding: 0 2px; }
.moves:empty { display: none; }
.moves {
  list-style: none; margin: 0; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); max-height: 220px; overflow-y: auto;
  display: grid; grid-template-columns: 1.2em 1fr; gap: 2px 8px; align-items: center;
  font: 15px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.moves .n { width: .8em; height: .8em; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--muted); }
.moves .n.w { background: #f3efe5; }
.moves .n.b { background: #232120; }
.moves .cur { color: var(--accent); font-weight: 700; }
@media (max-width: 899px) { .moves { max-height: 110px; } }

/* Phones and tablets: once the game is on, everything fits the screen without scrolling.
   The board takes whatever height is left; the move list is a single line that scrolls sideways. */
@media (max-width: 899px) {
  body.fit { height: 100dvh; display: flex; flex-direction: column; overflow-y: auto; }
  body.fit .top { flex: none; width: 100%; padding-top: 6px; padding-bottom: 6px; }
  body.fit .game { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: 10px; }
  body.fit .layout { flex: 1 1 auto; min-height: 0; gap: 8px; }
  body.fit .players, body.fit .side { flex: none; }
  body.fit .side { gap: 8px; }
  body.fit .boardcol {
    flex: 1 1 0; min-height: 200px; width: 100%; max-width: 720px;
    container-type: size; display: flex; align-items: center; justify-content: center;
  }
  body.fit .board { --size: min(100cqw, 100cqh * 7 / 6); }
  body.fit .status { padding: 8px 12px; }
  body.fit .moves {
    display: flex; gap: 10px; max-height: none; overflow-x: auto; overflow-y: hidden;
    white-space: nowrap; padding: 6px 10px; scrollbar-width: none;
  }
  body.fit .moves::-webkit-scrollbar { display: none; }
  body.fit .moves li { flex: none; }
  body.fit .moves:empty { display: none; }
  body.fit .moves li { align-self: center; }
  body.fit .moves .n { margin-right: -4px; }
}
@media (max-width: 899px) and (max-height: 720px) {
  body.fit .rules { display: none; }
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

/* Home screen extras: resume link, footer */
.resume { width: 100%; margin: 0 0 20px; border-color: var(--accent); }
/* Joining with a short code */
.join {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 0 0 22px;
}
.join label { display: block; font-weight: 700; margin-bottom: 8px; }
.joinrow { display: flex; gap: 8px; }
.joinrow input { flex: 1; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.joinrow input::placeholder { color: var(--muted); opacity: .6; font-weight: 400; }
.join-error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.foot { margin-top: 28px; text-align: center; font-size: 14px; }

/* Header: language switch (flags only) next to "New game" */
.top-actions { display: flex; align-items: center; gap: 10px; }
.langs { display: inline-flex; align-items: center; gap: 6px; }
.flag {
  appearance: none; border: 0; background: none; padding: 6px 2px; margin: 0; cursor: pointer; line-height: 0;
  opacity: .45; transition: opacity .15s;
}
.flag svg { display: block; width: 26px; height: 17px; border-radius: 3px; box-shadow: 0 0 0 1px var(--line); }
.flag:hover { opacity: .8; }
.flag[aria-pressed=true] { opacity: 1; cursor: default; }
.flag[aria-pressed=true] svg { box-shadow: 0 0 0 1px var(--bg), 0 0 0 3px var(--accent); }
.flag:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Foot of the home screen: "Language" opens the list of every language */
.foot { color: var(--muted); }
.foot-link {
  appearance: none; border: 0; background: none; padding: 0; margin: 0; font: inherit; color: var(--muted);
  text-decoration: underline; cursor: pointer;
}
.foot-link:hover { color: var(--text); }
.foot-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.lang-all { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.lang-all[hidden] { display: none; }
.flag.named {
  display: inline-flex; align-items: center; gap: 8px; opacity: 1; line-height: 1.2; font: inherit; font-size: 14px;
  color: var(--text); padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.flag.named svg { width: 22px; height: 14px; box-shadow: 0 0 0 1px var(--line); }
.flag.named:hover { border-color: var(--muted); }
.flag.named[aria-pressed=true] { border-color: var(--accent); font-weight: 600; }

/* Header: voice chat — the microphone and, while voice is on, a button to leave */
.voice { display: inline-flex; align-items: center; gap: 6px; }
.btn.icon { padding: 6px; min-width: 36px; }
.btn.icon svg, .voice-mark svg {
  display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
#voice-mic.on { border-color: var(--accent); color: var(--accent); }
#voice-mic.on.linked { background: var(--ok); border-color: var(--ok); color: #10210f; }
#voice-mic.on.muted { background: transparent; border-color: var(--danger); color: var(--danger); }
#voice-mic.calling { border-color: var(--ok); color: var(--ok); animation: voice-call 1.6s ease-out infinite; }
@keyframes voice-call {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  to { box-shadow: 0 0 0 9px transparent; }
}
@media (prefers-reduced-motion: reduce) { #voice-mic.calling { animation: none; } }
.voice-mark { flex: none; color: var(--muted); line-height: 0; }
.voice-mark svg { width: 14px; height: 14px; }
.voice-mark.linked { color: var(--ok); }
/* Narrow phones: the header keeps the die only, so the voice buttons fit */
@media (max-width: 430px) {
  body.has-voice .brand [data-i18n] { display: none; }
  body.has-voice .top-actions { gap: 8px; }
}
