/* Dots and Boxes (kutular) — notebook-paper board, ink dots and lines, coral / blue claimed boxes (prefix kb-).
 * Geometry: the board is one square SVG sized by CSS only (width of .kb-wrap); score pills and the note slot above it
 * have fixed heights, so nothing that changes during play (scores, notes, turn) can move or resize the board. */
.kb-wrap {
  --kb-paper: var(--surface); --kb-grid: rgba(61, 123, 247, .07); --kb-ink: var(--ink); --kb-track: var(--line-2);
  --kb-p0: var(--brand); --kb-p1: var(--blue); --kb-p0-soft: var(--brand-soft); --kb-p1-soft: var(--blue-soft);
  /* viewport-only sizing: deliberately NOT reduced by the shell's --claim-h (the "opponent offline" line comes and
     goes during play and must never resize the board); svh ignores the mobile URL bar showing / hiding */
  width: min(100%, 520px, max(250px, calc(100vh - 344px)));
  width: min(100%, 520px, max(250px, calc(100svh - 344px)));
  gap: 6px;
}
:root[data-theme="dark"] .kb-wrap { --kb-grid: rgba(140, 170, 255, .06); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kb-wrap { --kb-grid: rgba(140, 170, 255, .06); } }

/* score pills: fixed size, digits are tabular, only colours change */
.kb-score { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 40px; flex: none; }
.kb-pill { display: flex; align-items: center; justify-content: center; gap: 8px; width: 96px; height: 36px; box-sizing: border-box; border-radius: 14px;
  background: var(--surface-2); border: 2px solid transparent; box-shadow: 0 3px 0 var(--line); transition: border-color .25s, background-color .25s; }
.kb-pill b { font-size: 21px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; color: var(--ink); width: 2ch; text-align: center; }
.kb-pill.kb-on.kb-p0 { border-color: var(--kb-p0); background: var(--kb-p0-soft); }
.kb-pill.kb-on.kb-p1 { border-color: var(--kb-p1); background: var(--kb-p1-soft); }
.kb-pill.kb-win { border-color: #f2b632; background: color-mix(in srgb, #ffd166 30%, var(--surface-2)); }
.kb-pill.kb-bump b { animation: kbbump .45s ease-out; }
@keyframes kbbump { 0% { color: var(--ink); } 30% { color: #f2a91f; } 100% { color: var(--ink); } }
.kb-vs { color: var(--ink-3); font-weight: 700; }
.kb-mini { width: 18px; height: 18px; border-radius: 6px; flex: none; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18); }
.kb-mini.p0 { background: var(--kb-p0); }
.kb-mini.p1 { background: var(--kb-p1); }

/* fixed-height slot: "+3 boxes" chip after a turn that claimed boxes (never moves the board) */
.kb-slot { height: 26px; width: 100%; flex: none; display: flex; align-items: center; justify-content: center; min-width: 0; overflow: hidden; }
.kb-note { max-width: calc(100% - 8px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 800; line-height: 1.2; color: var(--ink); background: var(--surface); border: 2px solid var(--line-2);
  border-radius: 999px; padding: 1px 12px 1px 8px; box-shadow: 0 2px 0 var(--line-2); animation: kbnote .35s var(--spring, ease-out) both; }
.kb-note.r0 { border-color: color-mix(in srgb, var(--kb-p0) 55%, var(--line-2)); }
.kb-note.r1 { border-color: color-mix(in srgb, var(--kb-p1) 55%, var(--line-2)); }
.kb-note .kb-mini { width: 12px; height: 12px; border-radius: 4px; }
@keyframes kbnote { from { transform: scale(.85); opacity: 0; } }

/* the board: a sheet of squared paper on a chunky card */
.kb-frame { position: relative; width: 100%; flex: none; box-sizing: border-box; padding: 6px; border-radius: 18px; background: var(--kb-paper);
  border: 2px solid var(--line-2); box-shadow: 0 6px 0 var(--line), var(--shadow, 0 10px 24px rgba(0, 0, 0, .12)); transition: box-shadow .3s, border-color .3s; }
/* touch: a vertical swipe on the board scrolls the page (the browser cancels the pointer, so no line is drawn);
   a tap draws. kutular.js also refuses a release that is off the pressed line or half a cell away from the press. */
.kb-svg { display: block; width: 100%; height: auto; aspect-ratio: 1; touch-action: pan-y pinch-zoom; cursor: default; border-radius: 12px;
  background-color: var(--kb-paper);
  background-image: linear-gradient(var(--kb-grid) 1px, transparent 1px), linear-gradient(90deg, var(--kb-grid) 1px, transparent 1px);
  background-size: calc(100% / 11.36) calc(100% / 11.36); background-position: 6.564% 6.564%; -webkit-tap-highlight-color: transparent; }
.kb-wrap.mine .kb-svg { cursor: pointer; }
.kb-wrap.mine .kb-frame { border-color: color-mix(in srgb, var(--kb-p0) 60%, var(--line-2)); box-shadow: 0 6px 0 var(--line), 0 0 0 4px var(--brand-soft), var(--shadow, 0 10px 24px rgba(0, 0, 0, .12)); }
.kb-wrap.mine.p1 .kb-frame { border-color: color-mix(in srgb, var(--kb-p1) 60%, var(--line-2)); box-shadow: 0 6px 0 var(--line), 0 0 0 4px var(--blue-soft), var(--shadow, 0 10px 24px rgba(0, 0, 0, .12)); }

/* free lines: a faint dashed guide between the dots */
.kb-track { stroke: var(--kb-track); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 2 12; opacity: .9; }
.kb-track.gone { opacity: 0; }

/* drawn lines: ink; the lines of the latest turn in the colour of the player who drew them */
.kb-line { stroke: var(--kb-ink); stroke-width: 11; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 0; opacity: 0; }
.kb-line.on { opacity: 1; }
.kb-line.run.r0 { stroke: var(--kb-p0); }
.kb-line.run.r1 { stroke: var(--kb-p1); }
.kb-wrap.over .kb-line.run { stroke: var(--kb-ink); }
.kb-lastmark { fill: none; stroke-width: 5; opacity: 0; pointer-events: none; }
.kb-lastmark.on { opacity: 1; stroke: #fff; animation: kbmark 1.4s ease-in-out infinite alternate; }
.kb-lastmark.on.r0 { fill: var(--kb-p0); }
.kb-lastmark.on.r1 { fill: var(--kb-p1); }
.kb-wrap.over .kb-lastmark { opacity: 0; }
@keyframes kbmark { from { stroke-opacity: 1; } to { stroke-opacity: .35; } }

/* preview of the line you are about to draw */
.kb-preview { stroke-width: 13; stroke-linecap: round; opacity: 0; pointer-events: none; transition: opacity .1s; }
.kb-preview.p0 { stroke: var(--kb-p0); }
.kb-preview.p1 { stroke: var(--kb-p1); }
.kb-preview.on { opacity: .5; }
.kb-preview.on.kbd { opacity: .75; }
.kb-preview.cursor { stroke: var(--ink-3); opacity: .45; stroke-width: 17; }

.kb-dot { fill: var(--kb-ink); stroke: var(--kb-paper); stroke-width: 3; }

/* claimed boxes */
.kb-box { opacity: 0; transform-box: fill-box; transform-origin: center; pointer-events: none; }
.kb-box.own { opacity: 1; }
.kb-box.o0 .kb-fill { fill: var(--kb-p0-soft); stroke: color-mix(in srgb, var(--kb-p0) 35%, transparent); stroke-width: 2; }
.kb-box.o1 .kb-fill { fill: var(--kb-p1-soft); stroke: color-mix(in srgb, var(--kb-p1) 35%, transparent); stroke-width: 2; }
.kb-box.o0 .kb-tok { fill: var(--kb-p0); }
.kb-box.o1 .kb-tok { fill: var(--kb-p1); }
.kb-tok-hi { fill: rgba(255, 255, 255, .55); }
.kb-box .kb-tok { filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .18)); }

/* keyboard targets: invisible, the preview line shows the focused one */
.kb-key { stroke: transparent; stroke-width: 40; fill: none; pointer-events: none; outline: none; }
.kb-key:focus { outline: none; }

@media (max-width: 560px) {
  .kb-frame { padding: 4px; border-radius: 16px; }
}
/* short screens (small phones, landscape): a more compact score strip so the board keeps its size */
@media (max-height: 620px) {
  .kb-wrap { gap: 4px; }
  .kb-score { height: 34px; }
  .kb-pill { height: 32px; }
  .kb-pill b { font-size: 19px; }
  .kb-slot { height: 22px; }
  .kb-note { font-size: 12px; }
}
/* turn cue beside the board: only on short landscape screens (below) */
.kb-turn { display: none; }

/* phones on their side (height ≤ 420 px): score pills and the turn cue sit in a narrow column LEFT of the board,
   the board is sized from the height left under the sticky header, so after the one-time scroll in kutular.js
   (scroll-margin keeps it clear of the header) score, turn and the whole board are on screen together */
@media (orientation: landscape) and (max-height: 420px) {
  .kb-wrap {
    --kb-b: min(520px, max(250px, calc(100vh - 78px)));
    --kb-b: min(520px, max(250px, calc(100svh - 78px)));
    width: auto; max-width: 100%;
    display: grid; grid-template-columns: 112px var(--kb-b); grid-template-rows: auto auto 1fr; column-gap: 14px; row-gap: 8px;
    align-items: start; justify-content: center; scroll-margin-top: 66px;
  }
  .kb-score { grid-column: 1; grid-row: 1; flex-direction: column; height: auto; gap: 6px; }
  .kb-vs { display: none; }
  .kb-pill { width: 100%; height: 38px; }
  .kb-turn { display: flex; grid-column: 1; grid-row: 2; height: 58px; align-items: center; justify-content: center; text-align: center;
    box-sizing: border-box; padding: 4px 6px; border-radius: 12px; font-size: 13px; font-weight: 800; line-height: 1.2; color: var(--ink-3);
    overflow: hidden; border: 2px solid transparent; }
  .kb-turn.me.t0 { color: var(--kb-p0); border-color: color-mix(in srgb, var(--kb-p0) 45%, transparent); }
  .kb-turn.me.t1 { color: var(--kb-p1); border-color: color-mix(in srgb, var(--kb-p1) 45%, transparent); }
  .kb-slot { grid-column: 1; grid-row: 3; height: 26px; }
  .kb-note { padding: 1px 8px 1px 6px; }
  .kb-frame { grid-column: 2; grid-row: 1 / span 3; width: var(--kb-b); }
}

/* room: the shell's "opponent offline · claim the win" line (#claimLine, app.js) normally takes a row above the board
   while it shows, which would push the board down. Here it floats as a banner over the opponent's bar instead (the
   message is about that player), so the board never moves. Same idea as amiral.css. */
#boardPanel:not(.rs-fit):has(.kb-wrap) > #claimLine { position: absolute; z-index: 3; top: 14px; left: 14px; right: 14px; height: 52px; margin: 0;
  box-sizing: border-box; padding: 4px 12px; border-radius: 16px; background: var(--surface); border: 2px solid var(--brand);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .14); overflow: hidden; font-size: 13px; line-height: 1.25; }
#boardPanel:not(.rs-fit):has(.kb-wrap) > #claimLine.hidden { display: none; }
@media (max-width: 640px) { #boardPanel:not(.rs-fit):has(.kb-wrap) > #claimLine { top: 8px; left: 8px; right: 8px; } }

@media (prefers-reduced-motion: reduce) {
  .kb-note, .kb-lastmark.on, .kb-pill.kb-bump b { animation: none; }
  .kb-pill, .kb-frame, .kb-preview { transition: none; }
}

/* wave16 integration: in rooms on phones held sideways the shell (games.css) puts the board in a right-hand column
   whose width comes from the screen height (--lh) minus --board-xl. The score column + board here are 138 px wider
   than that height, so the column is widened by that much (no horizontal overflow; sizes depend on the viewport only). */
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  #board:has(> .kb-wrap) { --board-xl: -138px; }
}
/* wave16 fix: that 138 px came out of the player bars' column (names cut to nothing, the score drawn over the pills at
   568 px). In rooms held sideways the bars already carry both scores, the colour chips and the turn, and the status line
   says whose turn it is, so the board's own score / turn column is left out there and the board column is only the
   frame (kb-b = 100svh - 78px = --lh + 12px). Applies to rooms and the vs-computer page (both body.in-room). */
@media (max-width: 960px) and (max-height: 420px) and (orientation: landscape) {
  body.in-room #board:has(> .kb-wrap) { --board-xl: -12px; }
  body.in-room .kb-wrap { grid-template-columns: var(--kb-b); column-gap: 0; }
  body.in-room .kb-wrap > :is(.kb-score, .kb-turn, .kb-slot) { display: none; }
  body.in-room .kb-wrap > .kb-frame { grid-column: 1; }
}
/* wave16 integration: phone rooms (portrait) with the chat bar under the own player bar: 28 px less board height so
   the whole stage (bars, board, chat bar) fits one 640 px screen; sizes still come from the viewport only */
@media (max-width: 640px) and (orientation: portrait) {
  body.in-room .kb-wrap { width: min(100%, 520px, max(250px, calc(100vh - 372px))); width: min(100%, 520px, max(250px, calc(100svh - 372px))); }
}

/* wave19 room shell (room.css, BO_FIT_GAMES): the shell sizes #board (full width on portrait phones, full height beside
   the player bars in landscape); the wrap fills it. Block = score pills 40 + gap 6 + note slot 26 + gap 6 + the square
   frame, so --board-x 78 px. Phones held sideways: the bars in the column carry both scores and the turn, the pills and
   the slot are left out (--board-x 0). All fixed heights: nothing that changes in play moves the board. */
body.in-room #boardPanel.rs-fit > #board:has(> .kb-wrap) { --board-ar: 1; --board-x: 78px; }
body.in-room #boardPanel.rs-fit > #board > .kb-wrap { width: 100%; max-width: none; display: flex; flex-direction: column; gap: 6px; scroll-margin-top: 0; }
body.in-room #boardPanel.rs-fit > #board > .kb-wrap > .kb-score { height: 40px; flex-direction: row; }
body.in-room #boardPanel.rs-fit > #board > .kb-wrap .kb-pill { width: 96px; height: 36px; }
body.in-room #boardPanel.rs-fit > #board > .kb-wrap > .kb-slot { height: 26px; }
body.in-room #boardPanel.rs-fit > #board > .kb-wrap > .kb-frame { width: 100%; }
body.in-room #boardPanel.rs-fit > #board > .kb-wrap > .kb-turn { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room #boardPanel.rs-fit > #board:has(> .kb-wrap) { --board-x: 0px; }
  body.in-room #boardPanel.rs-fit > #board > .kb-wrap > :is(.kb-score, .kb-slot, .kb-turn) { display: none; }
}
