/* Backgammon table — Dev host + invite-only join
   Author: Dave Greenlaw */

.bg-app {
  --bg-felt: var(--crib-felt, color-mix(in srgb, #14532d 42%, var(--surface, #f5f6f8)));
  --bg-pt-a: #c45c42;
  --bg-pt-b: #cbb890;
  --bg-wood: color-mix(in srgb, #6b3f24 70%, var(--surface, #f5f6f8));
  --bg-man-w: #fffef8;
  --bg-man-w-ring: #1a1410;
  --bg-man-b: #161616;
  --bg-man-b-ring: #f4efe6;
  --bg-die-face: #fffef8;
  --bg-die-spent: #e6dcc8;
  --bg-die-pip: #161616;
  --bg-die-ring: #3d342c;
  --bg-felt-hi: color-mix(in srgb, var(--bg-felt) 78%, #fff);
}

.bg-app > .crib-status {
  display: none !important;
}

.bg-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 260px);
  flex: 1 1 auto;
  min-height: 0;
}

.bg-stage {
  padding: 10px 10px 16px;
  min-height: 0;
}

.bg-table {
  position: relative;
  border-radius: 22px;
  background:
    radial-gradient(120% 90% at 50% 30%, var(--bg-felt-hi, var(--bg-felt)), var(--bg-felt));
  border: 1px solid var(--crib-felt-line, var(--border));
  box-shadow:
    0 16px 36px color-mix(in srgb, var(--text, #000) 16%, transparent),
    inset 0 1px 0 color-mix(in srgb, var(--surface, #fff) 22%, transparent);
  padding: 10px 12px 14px;
  display: grid;
  grid-template-areas:
    "score"
    "board"
    "dice"
    "actions";
  gap: 10px;
  min-height: 0;
  color: var(--text, #1a1a1a);
}

.bg-score-bar {
  grid-area: score;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 6px;
  padding: 3px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface, #fff) 72%, transparent);
  border: 1px solid var(--border, #ccc);
  color: var(--text, #1a1a1a);
}

.bg-score-bar[hidden] {
  display: none;
}

.bg-score-bar__side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  line-height: 1.2;
}

.bg-score-bar__side.is-opp {
  justify-content: flex-end;
  text-align: right;
}

.bg-score-bar__side.is-empty {
  color: var(--text-muted, #5c6470);
  font-size: 0.78rem;
}

.bg-score-bar__side.is-turn {
  background: color-mix(in srgb, var(--accent, #2563eb) 22%, var(--surface, #fff));
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent, #2563eb) 40%, transparent);
}

.bg-score-bar__side.is-winner {
  border-color: var(--accent, #2563eb);
}

.bg-score-bar__who {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.bg-score-bar__man {
  width: 0.7rem;
  height: 0.7rem;
  flex: 0 0 auto;
}

.bg-score-bar__name {
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bg-score-bar__side.is-turn .bg-score-bar__name {
  font-weight: 800;
}

.bg-score-bar__tag {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent, #2563eb);
}

.bg-score-bar__nums {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  font-size: 0.78rem;
  color: var(--text, #1a1a1a);
}

.bg-score-bar__stat strong {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.bg-score-bar__mid {
  align-self: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted, #5c6470);
  white-space: nowrap;
}

.bg-board {
  grid-area: board;
  display: grid;
  grid-template-columns: minmax(2.6rem, 3.4rem) minmax(0, 1fr) minmax(3.2rem, 4.2rem) minmax(0, 1fr) minmax(2.6rem, 3.4rem);
  grid-template-rows: minmax(9.5rem, 1fr) minmax(9.5rem, 1fr);
  grid-template-areas:
    "offopp tl bar tr offyou"
    "offopp bl bar br offyou";
  gap: 4px;
  min-height: 20rem;
  padding: 6px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg-wood) 70%, var(--bg-felt));
  border: 2px solid color-mix(in srgb, var(--bg-wood) 80%, var(--border));
}

.bg-off-col--opp { grid-area: offopp; }
.bg-off-col--you { grid-area: offyou; }
.bg-bar-col { grid-area: bar; }
.bg-quad--tl { grid-area: tl; }
.bg-quad--tr { grid-area: tr; }
.bg-quad--bl { grid-area: bl; }
.bg-quad--br { grid-area: br; }

.bg-quad {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 2px;
  min-height: 0;
}

.bg-point {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 9rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: default;
  appearance: none;
}

.bg-point.is-legal,
.bg-point.is-dest,
.bg-point[data-bg-pt] {
  cursor: pointer;
}

.bg-point__tri {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bg-point--top .bg-point__tri {
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  background: var(--bg-pt-a);
}

.bg-point--bot .bg-point__tri {
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
  background: var(--bg-pt-a);
}

.bg-point--b .bg-point__tri {
  background: var(--bg-pt-b);
}

.bg-point.is-legal .bg-point__tri {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent, #2563eb) 70%, transparent);
}

.bg-point.is-from .bg-point__tri {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: -2px;
}

.bg-point.is-dest .bg-point__tri {
  filter: brightness(1.18);
  box-shadow: inset 0 0 0 3px var(--accent, #2563eb);
}

.bg-point__men {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  pointer-events: none;
}

.bg-point--top .bg-point__men {
  justify-content: flex-start;
  padding-top: 4px;
}

.bg-point--bot {
  align-items: flex-end;
}

.bg-point--bot .bg-point__men {
  justify-content: flex-end;
  flex-direction: column-reverse;
  padding-bottom: 4px;
}

.bg-point__n {
  position: absolute;
  z-index: 2;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  font-weight: 700;
  color: color-mix(in srgb, var(--text) 80%, var(--surface));
  pointer-events: none;
  text-shadow: 0 1px 0 color-mix(in srgb, var(--surface) 70%, transparent);
}

.bg-point--top .bg-point__n { bottom: 2px; }
.bg-point--bot .bg-point__n { top: 2px; }

.bg-man {
  display: inline-block;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  box-sizing: border-box;
  flex: 0 0 auto;
  isolation: isolate;
  mix-blend-mode: normal;
  opacity: 1;
  forced-color-adjust: none;
}

.bg-man--w {
  background: var(--bg-man-w, #fffef8);
  border: 2px solid var(--bg-man-w-ring, #1a1410);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.bg-man--b {
  background: var(--bg-man-b, #161616);
  border: 2px solid var(--bg-man-b-ring, #f4efe6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.bg-man-more {
  font-size: 0.65rem;
  font-weight: 800;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border-radius: 999px;
  padding: 0 4px;
}

.bg-bar-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  background: color-mix(in srgb, var(--bg-wood) 40%, var(--bg-felt));
  border-radius: 8px;
  padding: 4px 3px;
}

.bg-off-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: color-mix(in srgb, var(--bg-wood) 40%, var(--bg-felt));
  border-radius: 8px;
  padding: 4px 3px;
}

.bg-off-col .bg-tray {
  flex: 1 1 auto;
  min-height: 0;
  justify-content: center;
}

.bg-tray {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
  border: 1px dashed color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface, #fff) 35%, transparent);
  color: var(--text);
  min-height: 4.2rem;
}

button.bg-tray {
  cursor: pointer;
  appearance: none;
  font: inherit;
}

.bg-tray.is-legal,
.bg-tray.is-dest {
  border-style: solid;
  border-color: var(--accent, #2563eb);
}

.bg-tray.is-from {
  box-shadow: 0 0 0 2px var(--accent, #2563eb);
}

.bg-tray__label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #5c6470);
}

.bg-tray__men {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
}

.bg-tray__n {
  font-size: 0.75rem;
  font-weight: 700;
}

.bg-tray__pips {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-top: 2px;
  padding: 3px 4px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface, #fff) 82%, transparent);
  border: 1px solid var(--border, #ccc);
  color: var(--text, #1a1a1a);
  line-height: 1.1;
}

.bg-tray__pips strong {
  font-size: 0.85rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.bg-tray__pips small {
  font-size: 0.55rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted, #5c6470);
}

.bg-dice {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.bg-dice-strip {
  grid-area: dice;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface, #fff) 78%, transparent);
  border: 1px solid var(--border, #ccc);
  color: var(--text);
}

.bg-dice-strip[hidden] {
  display: none;
}

.bg-dice--strip .bg-die {
  width: 2.15rem;
  height: 2.15rem;
}

.bg-dice__cap {
  font-size: 0.8rem;
  font-weight: 700;
}

.bg-die {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 1.7rem;
  height: 1.7rem;
  padding: 3px;
  border-radius: 5px;
  color-scheme: light;
  isolation: isolate;
  mix-blend-mode: normal;
  opacity: 1;
  forced-color-adjust: none;
  background: var(--bg-die-face, #fffef8);
  border: 1px solid var(--bg-die-ring, #3d342c);
  color: var(--bg-die-pip, #161616);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.bg-die:not(.is-live) {
  background: var(--bg-die-spent, #e6dcc8);
  opacity: 1;
}

.bg-die.is-live {
  background: var(--bg-die-face, #fffef8);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 0 0 2px color-mix(in srgb, var(--accent, #2563eb) 55%, transparent);
}

.bg-die__pip {
  width: 0.28rem;
  height: 0.28rem;
  margin: auto;
  border-radius: 50%;
  background: var(--bg-die-pip, #161616);
}

.bg-dice__wait,
.bg-dice__left {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text);
}

.bg-cube {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 2rem;
  min-height: 2rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--surface) 70%, #c4b5a0);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 800;
  font-size: 0.85rem;
  line-height: 1;
}

.bg-cube small {
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--text-muted, #5c6470);
}

.bg-cube.is-off,
.bg-cube.is-crawford {
  font-size: 0.65rem;
  font-weight: 700;
}

.bg-you-bar {
  grid-area: youbar;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface, #fff) 78%, transparent);
  border: 1px solid var(--border, #ccc);
  color: var(--text);
}

.bg-you-bar[hidden] {
  display: none;
}

.bg-you-bar__label {
  font-size: 0.75rem;
  color: var(--text-muted, #5c6470);
}

.bg-you-bar__n {
  font-size: 1.15rem;
  font-weight: 800;
}

.bg-you-bar__side {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
}

.bg-you-bar__pips {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text, #1a1a1a);
}

.bg-actions {
  grid-area: actions;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  min-height: 2.2rem;
}

.bg-table .fk-over-stamp {
  grid-area: board;
  z-index: 6;
  pointer-events: none;
  justify-self: center;
  align-self: center;
  max-width: min(22rem, 94%);
  text-align: center;
}

.bg-table.is-between .fk-over-stamp {
  transform: rotate(-3deg);
}

.bg-over-stamp__tally {
  display: block;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text, #1a1a1a);
  text-transform: none;
  letter-spacing: 0;
}

html[data-theme="dark"] .bg-dice-strip,
html[data-theme="soft"] .bg-dice-strip,
html[data-theme="glass"] .bg-dice-strip,
html[data-theme="dark"] .bg-match-status,
html[data-theme="soft"] .bg-match-status,
html[data-theme="glass"] .bg-match-status,
html[data-theme="dark"] .bg-pip-hud,
html[data-theme="soft"] .bg-pip-hud,
html[data-theme="glass"] .bg-pip-hud,
html[data-theme="dark"] .bg-you-bar,
html[data-theme="soft"] .bg-you-bar,
html[data-theme="glass"] .bg-you-bar,
html[data-theme="dark"] .bg-seat__score,
html[data-theme="soft"] .bg-seat__score,
html[data-theme="glass"] .bg-seat__score,
html[data-theme="dark"] .bg-tray__pips,
html[data-theme="soft"] .bg-tray__pips,
html[data-theme="glass"] .bg-tray__pips {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  color: var(--text);
}

html[data-a11y-view="contrast"] .bg-match-status,
html[data-a11y-view="contrast"] .bg-pip-hud,
html[data-a11y-view="contrast"] .bg-you-bar,
html[data-a11y-view="contrast"] .bg-seat__score,
html[data-a11y-view="contrast"] .bg-tray__pips,
html[data-a11y-view="contrast"] .bg-point.is-dest .bg-point__tri,
html[data-a11y-view="contrast"] .bg-tray.is-dest {
  border-width: 2px;
}

html[data-a11y-view="comfort"] .bg-man {
  width: 1.4rem;
  height: 1.4rem;
}

html[data-a11y-view="comfort"] .bg-board {
  min-height: 24rem;
}

html[data-theme="glass"] .bg-table {
  --bg-felt: color-mix(in srgb, #166534 55%, #0c1210);
  border-color: var(--glass-edge, var(--border));
}

html[data-theme="dark"] .bg-over-stamp__tally,
html[data-theme="soft"] .bg-over-stamp__tally,
html[data-theme="glass"] .bg-over-stamp__tally {
  color: var(--text, #f8fafc);
}

@media (max-width: 720px) {
  .bg-main {
    grid-template-columns: 1fr;
  }

  .bg-board {
    min-height: 16rem;
    grid-template-columns: minmax(2.1rem, 2.6rem) minmax(0, 1fr) minmax(2.6rem, 3.2rem) minmax(0, 1fr) minmax(2.1rem, 2.6rem);
  }

  .bg-point {
    min-height: 7.2rem;
  }

  .bg-man {
    width: 0.95rem;
    height: 0.95rem;
  }

  .bg-pip-hud__n {
    font-size: 1.35rem;
  }
}
