/* ---- The backgammon table ---- */
#backgammon { max-width: 760px; margin: 0 auto; }
#bg-title { text-align: center; font-weight: 700; font-size: 0.9rem; padding: 0 48px; min-height: 1.3em; margin-bottom: 6px; }
/* The board is a little wider than it is tall; on a low screen it is the height that decides its size. */
#bg-board-wrap, #backgammon .bg-bar { width: min(100%, calc((100dvh - 330px) * 1.33)); min-width: 250px; margin-left: auto; margin-right: auto; }
#bg-board { border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); line-height: 0; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
#bg-svg { display: block; width: 100%; height: auto; touch-action: manipulation; }

/* The wood, the cloth and the points in two colours. */
#backgammon .bg-frame { fill: var(--t13); stroke: var(--t14); stroke-width: 2; }
#backgammon .bg-field { fill: var(--t9); }
#backgammon .bg-tray { fill: rgba(0, 0, 0, 0.35); stroke: transparent; stroke-width: 2; }
#backgammon .bg-pt-a { fill: #c9a56a; }
#backgammon .bg-pt-b { fill: #8c3b2f; }
#backgammon .bg-pt.bg-target { fill: var(--accent); }
#backgammon .bg-tray.bg-target { stroke: var(--accent); fill: rgba(var(--r1), 0.25); }

/* Checkers: seat 0 plays the light ones, seat 1 the dark ones. */
#backgammon .bg-ck.bg-s0 { fill: #f3ead6; stroke: #7d6c4c; }
#backgammon .bg-ck.bg-s1 { fill: #2b2422; stroke: #000; }
#backgammon .bg-ck { stroke-width: 1.5; }
#backgammon .bg-ck .bg-ck-in { fill: none; stroke-width: 1.2; opacity: 0.45; }
#backgammon .bg-ck.bg-s1 .bg-ck-in { stroke: #8a7d78; }
#backgammon .bg-ck.bg-can > circle:first-child { stroke: var(--accent); stroke-width: 3; }
#backgammon .bg-ck.bg-picked > circle:first-child { stroke: #7fd069; stroke-width: 4.5; }
#backgammon .bg-ck.bg-moved > circle:first-child { stroke: #6fb7e8; stroke-width: 2.5; }
#backgammon .bg-count { font: 700 15px system-ui, sans-serif; text-anchor: middle; pointer-events: none; }
#backgammon .bg-count.bg-s0 { fill: #2b2422; }
#backgammon .bg-count.bg-s1 { fill: #f3ead6; }
/* Where the checker I picked up can go. */
#backgammon .bg-mark { fill: #7fd069; stroke: #14320d; stroke-width: 1.5; opacity: 0.95; pointer-events: none; }
#backgammon .bg-mark.bg-hit { fill: none; stroke: #ff5a4d; stroke-width: 4; }
#backgammon .bg-zone { fill: transparent; cursor: pointer; }

/* Dice and the cube. */
#backgammon .bg-die rect { stroke-width: 1.5; }
#backgammon .bg-die.bg-s0 rect { fill: #fbf7ec; stroke: #7d6c4c; }
#backgammon .bg-die.bg-s0 circle { fill: #1c1c1c; }
#backgammon .bg-die.bg-s1 rect { fill: #2b2422; stroke: #000; }
#backgammon .bg-die.bg-s1 circle { fill: #f3ead6; }
#backgammon .bg-die.bg-used { opacity: 0.4; }
#backgammon .bg-die.bg-old { opacity: 0.28; }
#backgammon .bg-cube rect { fill: #f4f4f4; stroke: #555; stroke-width: 1.5; }
#backgammon .bg-cube text { font: 800 17px system-ui, sans-serif; text-anchor: middle; fill: #b3261e; pointer-events: none; }
#backgammon .bg-cube.bg-offered rect { fill: var(--t15); stroke: var(--accent); stroke-width: 3; }

/* The two players: picture, colour, name, points and pips. */
#backgammon .bg-bar { position: relative; display: flex; align-items: center; gap: 8px; margin-top: 6px; margin-bottom: 6px; padding: 4px 6px; border-radius: 10px; min-height: 46px; border: 1px solid transparent; }
#backgammon .bg-bar.bg-turn { border-color: var(--accent); background: rgba(255, 255, 255, 0.05); }
#backgammon .bg-bar.bg-vacant { cursor: pointer; }
#backgammon .bg-bar.bg-vacant .bg-name { text-decoration: underline; }
#backgammon .bg-cam { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: #000; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6); flex: none; }
#backgammon .bg-cam.bg-mirror { transform: none; /* my own picture is shown as the others see it, not mirrored */ }
#backgammon .bg-cam.blank { display: none; }
#backgammon .bg-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; border: 1.5px solid #7d6c4c; }
#backgammon .bg-dot.bg-s0 { background: #f3ead6; }
#backgammon .bg-dot.bg-s1 { background: #2b2422; border-color: #8a7d78; }
#backgammon .bg-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
#backgammon .bg-ready { font-size: 0.72rem; color: #1b1b1b; background: var(--t15); border-radius: 999px; padding: 1px 8px; font-weight: 700; flex: none; }
#backgammon .bg-stats { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; font-variant-numeric: tabular-nums; }
#backgammon .bg-score { font-weight: 700; font-size: 1.05rem; padding: 2px 9px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); }
#backgammon .bg-pips { font-size: 0.8rem; color: var(--muted); }
#backgammon .bg-bubble { position: absolute; left: 8px; top: calc(100% + 4px); z-index: 5; max-width: min(320px, 86%); background: #fdfdfd; color: #161616; border-radius: 12px; padding: 7px 11px; font-size: 0.88rem; font-weight: 600; line-height: 1.25; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); pointer-events: none; }
#backgammon .bg-bubble::after { content: ''; position: absolute; left: 18px; top: -12px; border: 6px solid transparent; border-bottom-color: #fdfdfd; }
#backgammon .bg-bubble.bg-up { top: auto; bottom: calc(100% + 4px); }
#backgammon .bg-bubble.bg-up::after { top: auto; bottom: -12px; border-bottom-color: transparent; border-top-color: #fdfdfd; }
#backgammon .bg-bubble.bg-pop { animation: bg-pop 0.22s ease-out; }
@keyframes bg-pop { from { transform: scale(0.7); opacity: 0; } }

/* Under the board. */
#bg-status { text-align: center; font-weight: 700; min-height: 1.5em; margin: 6px 0 2px; }
#bg-last { text-align: center; min-height: 1.2em; margin: 0; }
#bg-error { text-align: center; min-height: 1.2em; margin: 0; }
#bg-result { text-align: center; font-weight: 800; font-size: 1.1rem; margin: 6px auto; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--accent); max-width: 460px; }
#bg-result.bg-won { color: var(--t15); }
#bg-result.bg-lost { border-color: var(--danger); }
#backgammon .row { max-width: 460px; margin-left: auto; margin-right: auto; }
#bg-actions > button { min-height: 48px; }
#bg-offer { max-width: 460px; margin-left: auto; margin-right: auto; text-align: center; }
#bg-setup p { text-align: center; margin: 6px 0; }
#bg-bot { margin-top: 10px; }
#bg-bot-levels { flex-wrap: wrap; justify-content: center; }
#bg-bot-levels button { flex: 1 1 150px; }

@media (max-width: 699px) {
  /* Room on the right for the column of round buttons. */
  #backgammon { padding-top: 46px; } /* room for the row of round buttons along the top */
  #bg-title { padding: 0; }
  #bg-board-wrap, #backgammon .bg-bar { width: min(100%, calc((100dvh - 320px) * 1.33)); }
  #backgammon .bg-score { font-size: 0.95rem; padding: 2px 7px; }
  #backgammon .bg-stats { gap: 6px; }
}

@media (max-width: 699px) { #backgammon .bg-cam { width: 56px; height: 56px; } }
