/* Backgammon Arena - theme-aware, responsive. The board is a pure CSS/flex
   layout: two halves, four quadrants, triangular points (clip-path), a central
   bar, and off-trays. Checkers are bordered circles. */
:root {
  --bg: #0f1216; --panel: #181c22; --ink: #e8eaed; --muted: #9aa4b2;
  --felt: #2b3a34; --felt2: #24312c; --frame: #3a2b20; --frame2: #4a3626;
  --p-dark: #b6653f; --p-light: #d9b48a;
  --bar: #241a12; --accent: #6ea8fe; --line: #2a2f37; --good: #66d19e;
  --wc: #f2f4f8; --wc-edge: #23262b; --bc: #2b3038; --bc-edge: #05070a;
}
@media (prefers-color-scheme: light) {
  :root { --bg:#eef0f3; --panel:#ffffff; --ink:#1b1f24; --muted:#5b6572; --line:#e3e6ea;
          --felt:#3f5a4e; --felt2:#365046; --wc:#ffffff; --wc-edge:#42474e; --bc:#2a2f36; --bc-edge:#000; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
.boot, .arena { padding: 16px; }
.boot { color: var(--muted); }

.topbar h1 { font-size: 1.35rem; margin: 0 0 12px; font-weight: 650; }
.topbar .sub { color: var(--muted); font-weight: 400; font-size: .95rem; }

.layout { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.board-wrap { position: relative; display: flex; gap: 8px; }

/* ---- board frame ---- */
.board {
  width: min(94vw, 660px); aspect-ratio: 1.18; display: flex; flex-direction: column;
  background: var(--frame); border: 10px solid var(--frame2); border-radius: 10px;
  overflow: hidden; box-shadow: 0 8px 30px #0007; user-select: none; touch-action: manipulation;
}
.board.over { filter: saturate(.7) brightness(.92); }
.half { flex: 1 1 0; display: flex; min-height: 0; }
.half.top { background: var(--felt); }
.half.bottom { background: var(--felt2); }
.quad { flex: 1 1 0; display: flex; }

/* ---- points ---- */
.point { flex: 1 1 0; position: relative; cursor: default; }
.tri { position: absolute; inset: 0; z-index: 0; }
.ptop .tri { clip-path: polygon(0 0, 100% 0, 50% 94%); }
.pbot .tri { clip-path: polygon(50% 6%, 0 100%, 100% 100%); }
.pdark .tri { background: var(--p-dark); }
.plight .tri { background: var(--p-light); }

.point.src { cursor: pointer; }
.point.src .tri { box-shadow: inset 0 0 0 2px var(--good); filter: brightness(1.12); }
.point.tgt { cursor: pointer; }
.point.sel .tri { box-shadow: inset 0 0 0 3px var(--accent); filter: brightness(1.2); }

.stack { position: absolute; inset: 4% 0; z-index: 1; display: flex; flex-direction: column;
  align-items: center; }
.ptop .stack { justify-content: flex-start; }
.pbot .stack { justify-content: flex-end; }

.checker { width: 80%; aspect-ratio: 1; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: .62rem; font-weight: 700;
  flex: 0 0 auto; margin: -1px 0; }
.checker.wc { background: radial-gradient(circle at 38% 32%, #ffffff, var(--wc) 70%);
  border: 2px solid var(--wc-edge); color: #333; }
.checker.bc { background: radial-gradient(circle at 38% 32%, #4a525d, var(--bc) 72%);
  border: 2px solid var(--bc-edge); color: #dfe3e8; }

.point .dot { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 26%; aspect-ratio: 1; border-radius: 50%; background: #ffffffcc;
  box-shadow: 0 0 0 3px var(--accent); z-index: 3; }
.pnum { position: absolute; z-index: 2; font-size: 9px; font-weight: 700; color: #00000066;
  left: 0; right: 0; text-align: center; }
.ptop .pnum { top: 1px; } .pbot .pnum { bottom: 1px; }

/* ---- bar ---- */
.bar { width: 40px; flex: 0 0 40px; background: var(--bar); display: flex; flex-direction: column;
  align-items: center; gap: 1px; padding: 6px 0; }
.top-bar { justify-content: flex-start; }
.bot-bar { justify-content: flex-end; }
.bar.src { cursor: pointer; box-shadow: inset 0 0 0 2px var(--good); }
.bar.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.bar .checker { width: 30px; }

/* ---- off-trays ---- */
.offcol { display: flex; flex-direction: column; gap: 8px; justify-content: space-between; }
.off { width: 74px; flex: 1 1 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; position: relative; }
.off.white.tgt { cursor: pointer; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.offlbl { color: var(--muted); font-size: .72rem; }
.offnum { font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.off .dot.big { position: absolute; bottom: 8px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px var(--accent); }

/* ---- side panel ---- */
.panel { flex: 1 1 260px; min-width: 240px; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.status { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; min-height: 20px; }
.status.final { color: var(--accent); }
.spinner { width: 13px; height: 13px; border: 2px solid var(--muted); border-top-color: transparent;
  border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- dice ---- */
.dicerow { display: flex; gap: 10px; }
.die { width: 46px; height: 46px; background: #f4f5f7; border: 1px solid #cfd3d9; border-radius: 9px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 5px; box-shadow: 0 2px 5px #0004; }
.die.used { opacity: .34; }
.die.blank { display: flex; align-items: center; justify-content: center; background: var(--panel);
  border: 1px dashed var(--line); }
.die.blank .q { color: var(--muted); font-weight: 700; font-size: 1.2rem; }
.pip { display: block; }
.pip.on { align-self: center; justify-self: center; width: 9px; height: 9px; border-radius: 50%; background: #23272e; }

/* ---- HUD ---- */
.hud { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  display: flex; flex-direction: column; gap: 4px; }
.hrow { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; }
.hrow .k { font-weight: 650; }
.white-k { color: #dfe3e8; } .black-k { color: var(--muted); }
.hrow .v { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- controls ---- */
.controls { display: flex; flex-direction: column; gap: 8px; }
.ctl-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls button { background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 11px; cursor: pointer; font-size: .9rem; }
.controls button:hover:not(:disabled) { border-color: var(--accent); }
.controls button:disabled { opacity: .42; cursor: default; }
#roll-btn:not(:disabled) { background: var(--accent); color: #06121f; border-color: var(--accent); font-weight: 650; }
#end-btn:not(:disabled) { background: var(--good); color: #062016; border-color: var(--good); font-weight: 650; }
.controls label { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.controls select { background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px; }

/* ---- log ---- */
.logbox { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.log-head { padding: 8px 12px; font-weight: 600; border-bottom: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.log { max-height: 200px; overflow-y: auto; padding: 4px 0; }
.lrow { padding: 3px 12px; font-size: .82rem; font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }
.lrow.ai { color: var(--muted); }
.lrow.empty { color: var(--muted); font-family: inherit; }

.engine-note { color: var(--muted); font-size: .78rem; line-height: 1.4; }
.engine-note code { background: #ffffff10; padding: 1px 4px; border-radius: 4px; overflow-wrap: anywhere; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: #b33; color: #fff; padding: 8px 12px; z-index: 100; }
#blazor-error-ui .reload, #blazor-error-ui .dismiss { color: #fff; margin-left: 8px; cursor: pointer; }

@media (max-width: 680px) {
  .board { width: 96vw; }
  .offcol { gap: 6px; } .off { width: 54px; }
  .panel { max-width: none; }
}
