/* EwrekaGames — v19 room shell: the game screen of rooms (play.php) and vs-computer pages (bot.php).
   The board is the hero: the chrome (top bar, player bars, status line, chat bar, frames) is compacted to the minimum and
   the board gets the rest of the screen. Everything here is decided by CSS from the viewport only (svh / container
   width), once per viewport: nothing in it depends on game state, messages, chat, the result card or the on-screen
   keyboard (svh ignores it), so the board never changes size during play.
   Contract for the games: S/wave19/CONTRACT.md. In short:
   - #boardPanel.rs-fit (lib/site.php BO_FIT_GAMES): the shell sizes #board. A game's wrap is width: 100% of #board and
     declares on #boardPanel how much taller than wide it is: --board-ar (play surface height / width, default 1) and
     --board-x (fixed extra height: trays, score pills, button rows, default 0).
   - Every game may read --rs-bh (height available to the whole board block) on #boardPanel and its children.
   Loaded last on both pages (after games.css, chat.css, acq.css; a room's own game CSS is added later by app.js). */

/* ---------- tokens ---------- */
body.in-room {
  --rs-pad: 6px;      /* content padding above / below the stage on phones */
  --rs-gap: 6px;      /* gap between the stage's rows */
  --rs-bar: 40px;     /* compact player bar */
  --rs-st: 20px;      /* status line */
  --rs-chat: 50px;    /* chat bar (44) + its gap; 0 on vs-computer pages */
  --rs-col: 196px;    /* landscape: the column of player bars beside the board */
  --rs-menu: 46px;    /* portrait phones: the menu button left of the opponent's bar (40 + 6) */
}
body.in-room.bot-room { --rs-chat: 0px; }
body.in-room #boardPanel { --board-ar: 1; --board-x: 0px; }

/* per game: how the board block is taller than wide (FIT games; others: their own CSS) */
#boardPanel.rs-fit:has(#board .chess-wrap) { --board-x: 52px; }   /* the two captured-piece trays (22 px + 4 px gap each) */
#boardPanel.rs-fit:has(#board .dama-wrap) { --board-x: 0px; }
#boardPanel.rs-fit:has(#board .xox-board) { --board-x: 0px; }
#boardPanel.rs-fit:has(#board .d4-wrap) { --board-x: 8px; }      /* 7 x 6 holes + the drop row, in a frame */
#boardPanel.rs-fit:has(#board .gm-wrap) { --board-x: 64px; }      /* confirm bar under the board */
#boardPanel.rs-fit:has(#board .rv-wrap) { --board-x: 72px; }      /* score pills */

/* the FIT games' wraps take the width the shell gives #board */
body.in-room #boardPanel.rs-fit > #board > :is(.chess-wrap, .dama-wrap, .xox-board, .d4-wrap, .gm-wrap, .rv-wrap) { width: 100%; max-width: none; }
body.in-room #boardPanel.rs-fit > #board { max-width: none; gap: 6px; }
body.in-room #boardPanel.rs-fit .chess-wrap { gap: 4px; }
body.in-room #boardPanel.rs-fit .chess-wrap > .ctray { height: 22px; min-height: 0; overflow: hidden; }
body.in-room #boardPanel.rs-fit .chess-wrap > .ctray img { width: 20px; height: 20px; }

/* ---------- portrait (phones and portrait tablets): one column, the board as wide as the screen ---------- */
@media (max-width: 1080px) and (orientation: portrait) {
  body.in-room .content { padding: var(--rs-pad) 8px 24px; }
  body.in-room .stage#boardPanel { padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; gap: var(--rs-gap); min-height: 0; }
  body.in-room #boardPanel { --rs-bh: calc(100svh - 2 * var(--rs-pad) - 2 * var(--rs-bar) - var(--rs-st) - 3 * var(--rs-gap) - var(--rs-chat) - env(safe-area-inset-bottom, 0px)); }
  body.in-room #boardPanel.rs-fit > #board { width: min(100%, calc((var(--rs-bh) - var(--board-x)) / var(--board-ar))); margin-inline: auto; }
  /* the result card's veil ends above the chat bar (44 + 6) */
  body.in-room #boardPanel:has(> #chatBar:not([hidden])) > #result.result { bottom: var(--rs-chat); border-radius: 16px; }
  /* chat bar: its ring takes the page colour (there is no card around the stage any more) */
  body.in-room .chat-bar:not([hidden]) > .cb-in:not(.float) { background: var(--bg); box-shadow: 0 0 0 6px var(--bg); }
}
/* compact player bars and status line: portrait phones / tablets, and the FIT games on phones held sideways */
@media (max-width: 1080px) and (orientation: portrait), (max-height: 500px) and (orientation: landscape) {
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar { min-height: 0; height: var(--rs-bar); padding: 2px 10px 2px 4px; gap: 8px; border-radius: 12px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .avatar { width: 32px; height: 32px; border-radius: 10px; font-size: 15px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .pn b { font-size: 13.5px; line-height: 17px; gap: 6px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .pn b em { font-size: 10.5px; padding: 0 5px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .pn small { margin-top: 0; font-size: 11px; line-height: 14px; gap: 5px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .chip { width: 9px; height: 9px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .psc { font-size: 19px; min-width: 16px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .ptag { font-size: 0; gap: 0; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .ptag:not(.think)::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .ptag .typing { gap: 3px; }
  body.in-room .stage#boardPanel :is(#pTop, #pBottom).pbar .ptag .typing i { width: 5px; height: 5px; }
  body.in-room .stage#boardPanel > #status { height: var(--rs-st); min-height: 0; line-height: var(--rs-st); font-size: 13px; }
  /* chat bubbles: two lines inside the 40 px bar */
  body.in-room #boardPanel .chat-bub { padding: 3px 9px 3px 11px; font-size: 12.5px; line-height: 1.2; }
}

/* landscape tablets and desktop (FIT): the player bars sit in the narrow column beside the board: one tidy row each,
   the turn shown by the bar's colour and a dot (the "Your turn" word does not fit the column) */
@media (orientation: landscape) and (min-height: 501px) {
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar { min-height: 0; height: 56px; padding: 4px 12px 4px 6px; gap: 8px; border-radius: 14px; }
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar .pn b { font-size: 14px; gap: 6px; }
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar .psc { font-size: 22px; min-width: 18px; }
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar .ptag { font-size: 0; gap: 0; }
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar .ptag:not(.think)::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
  body.in-room .stage#boardPanel.rs-fit > #status { height: auto; min-height: 22px; max-height: 66px; white-space: normal; line-height: 22px; text-align: left; justify-content: flex-start; padding: 0 4px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
}

/* ---------- the site's top bar in rooms (phones, tablets up to 960 px): only its menu button stays, floating at the
   top left, beside the opponent's bar. The logo and the rest are in the menu. Portrait: every game; landscape: the
   FIT games (the others keep their landscape layouts with the bar for now) ---------- */
@media (max-width: 960px) and (orientation: portrait) {
  body.in-room .topbar { position: fixed; top: calc(env(safe-area-inset-top, 0px) + var(--rs-pad)); left: calc(env(safe-area-inset-left, 0px) + 8px); width: var(--rs-bar); height: var(--rs-bar); padding: 0; gap: 0; border: 0; background: transparent; z-index: 40; }
  body.in-room .topbar > :not(#menuBtn) { display: none !important; }
  body.in-room .topbar #menuBtn { width: var(--rs-bar); height: var(--rs-bar); margin: 0; border-radius: 12px; background: var(--surface-2); }
  body.in-room .stage#boardPanel #pTop { align-self: flex-end; width: calc(100% - var(--rs-menu)); }
  /* before the game (waiting / loading) and the first-visit language hint: nothing under the floating button */
  body.in-room .content:has(> #gameArea.hidden) { padding-top: calc(var(--rs-pad) + var(--rs-menu)); }
  body.in-room .main > .langhint { margin-left: calc(8px + var(--rs-menu)); }
}
@media (max-width: 960px) and (orientation: landscape) {
  body.in-room:has(#boardPanel.rs-fit) .topbar { position: fixed; top: calc(env(safe-area-inset-top, 0px) + var(--rs-pad)); left: calc(env(safe-area-inset-left, 0px) + 8px); width: var(--rs-bar); height: var(--rs-bar); padding: 0; gap: 0; border: 0; background: transparent; z-index: 40; }
  body.in-room:has(#boardPanel.rs-fit) .topbar > :not(#menuBtn) { display: none !important; }
  body.in-room:has(#boardPanel.rs-fit) .topbar #menuBtn { width: var(--rs-bar); height: var(--rs-bar); margin: 0; border-radius: 12px; background: var(--surface-2); }
  body.in-room .stage#boardPanel.rs-fit #pTop { margin-left: var(--rs-menu); width: auto; }
  body.in-room:has(#boardPanel.rs-fit) .content:has(> #gameArea.hidden) { padding-top: calc(var(--rs-pad) + var(--rs-menu)); }
  body.in-room:has(#boardPanel.rs-fit) .main > .langhint { margin-left: calc(8px + var(--rs-menu)); }
}

/* ---------- landscape (phones held sideways, landscape tablets, desktop): FIT games put the player bars, the status line
   and the chat bar in a column left of the board; the board takes the full height ---------- */
@media (orientation: landscape) {
  body.in-room { --rs-cpad: 12px; --rs-spad: 0px; }
  body.in-room #boardPanel.rs-fit {
    --rs-bh: calc(100svh - 2 * var(--rs-cpad) - 2 * var(--rs-spad));
    container-type: inline-size;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    column-gap: 14px; row-gap: var(--rs-gap); align-items: start; justify-items: stretch; min-height: 0;
  }
  body.in-room #boardPanel.rs-fit > #pTopRow { display: contents; }
  body.in-room #boardPanel.rs-fit #pTop { grid-column: 1; grid-row: 1; }
  body.in-room #boardPanel.rs-fit > #status { grid-column: 1; grid-row: 2; }
  body.in-room #boardPanel.rs-fit > #pBottom { grid-column: 1; grid-row: 4; align-self: end; }
  body.in-room #boardPanel.rs-fit > .chat-bar:not([hidden]) { grid-column: 1; grid-row: 5; position: relative; inset: auto; width: 100%; z-index: 26; }
  body.in-room #boardPanel.rs-fit > #board { grid-column: 2; grid-row: 1 / -1; margin: 0; align-self: center;
    width: max(160px, min(calc(100cqw - var(--rs-col) - 14px), calc((var(--rs-bh) - var(--board-x)) / var(--board-ar)))); }
  body.in-room #boardPanel.rs-fit > #result.result { inset: 0; bottom: 0; }
  /* the bar in the column: as under the board (its field on the page colour) */
  body.in-room #boardPanel.rs-fit > .chat-bar:not([hidden]) > .cb-in:not(.float) { background: transparent; box-shadow: none; }
  body.in-room #boardPanel.rs-fit > .chat-bar .cb-field { background: var(--surface-2); border-color: transparent; }
  body.in-room .main:has(#boardPanel.rs-fit) .content { padding-top: var(--rs-cpad); padding-bottom: var(--rs-cpad); }
  body.in-room .stage#boardPanel.rs-fit { padding: var(--rs-spad); }
}
/* phones held sideways: no frame, the smallest margins */
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room { --rs-cpad: 6px; }
  body.in-room .main:has(#boardPanel.rs-fit) .content { padding-left: 8px; padding-right: 8px; }
  body.in-room .stage#boardPanel.rs-fit { border: 0; border-radius: 0; background: none; box-shadow: none; }
}
/* landscape tablets (up to 1080 px: the side panel is under the board): no card around the stage */
@media (orientation: landscape) and (min-height: 501px) and (max-width: 1080px) {
  body.in-room .main:has(#boardPanel.rs-fit) .content { padding-left: 6px; padding-right: 6px; }
  body.in-room .stage#boardPanel.rs-fit { border: 0; border-radius: 0; background: none; box-shadow: none; }
  /* wave20 fix: was 220 (and 16 px gutters) in v19. Chess's trays and Reversi's score pills moved into the column, so the
     board block is the board alone and bound by the width here: column 168 px and 6 px gutters, 1024x768 square boards
     667 (v19) -> 739 px, the band under the board 12-17 px (v19: Reversi 17, Chess 37). */
  body.in-room { --rs-col: 168px; }
  /* the narrower column's bars: a smaller avatar and tighter insides, so the name keeps more letters */
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar { padding: 4px 8px 4px 5px; gap: 6px; }
  body.in-room .stage#boardPanel.rs-fit :is(#pTop, #pBottom).pbar .avatar { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
}
/* desktop: the stage keeps its card (12 px padding + 1 px border), the room may use a wide screen */
@media (min-width: 1081px) {
  body.in-room { --rs-spad: 13px; --rs-col: 230px; }
  body.in-room .main:has(#boardPanel.rs-fit) .content { max-width: 1680px; padding-left: 24px; padding-right: 24px; }
  body.in-room .stage#boardPanel.rs-fit { padding: 12px; }
  body.in-room .room-grid:has(> #boardPanel.rs-fit) { align-items: start; }
}

/* ---------- wave19 fix ---------- */
/* phones held sideways (FIT, the 196 px column): the chat bar takes two rows, the emoji row (4 whole emoji, swipe for
   the rest) over [chat button][field], so the reactions stay one tap away. The bar's height is fixed (94 px): typing
   hides the emoji only visually, docking over the keyboard takes the bar out of its place, nothing else moves. While the
   result card is shown the emoji row steps aside (hidden, taps go through), so only the field row stays over the card's
   veil, below the card. (Yut has its own wider column and 44 px bar.) */
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]) > .chat-bar:not([hidden]) { height: 94px; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) { flex-wrap: wrap; height: 94px; row-gap: 6px; align-content: flex-start; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { flex: 0 0 100%; width: 100%; order: -1; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]),
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) { pointer-events: none; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) > :not(.cb-rx) { pointer-events: auto; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { visibility: hidden; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]) > .chat-bar.typing:not([hidden]) > .cb-in:not(.float) > .cb-rx { display: flex; visibility: hidden; }
  body.in-room #boardPanel.rs-fit:not([data-game="yut"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .rx-cool { left: 0; bottom: auto; top: 45px; }
}
/* portrait phones: the floating menu button never covers the result card: it steps aside while the card is shown (the
   card keeps all of its room; its own buttons lead on) */
@media (max-width: 960px) and (orientation: portrait) {
  body.in-room:has(#boardPanel > #result.result:not(.hidden)) .topbar { visibility: hidden; }
}
/* phones held sideways: Gomoku's confirm bar and Reversi's score pills / pass note move from under the board into the
   column beside it (just under the status line), so the board takes the full height (--board-x 0). Fixed places,
   viewport only: nothing moves during play. */
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room #boardPanel.rs-fit:has(#board .gm-wrap), body.in-room #boardPanel.rs-fit:has(#board .rv-wrap) { --board-x: 0px; }
  body.in-room #boardPanel.rs-fit > #board:is(:has(> .gm-wrap), :has(> .rv-wrap)) { position: relative; }
  body.in-room #boardPanel.rs-fit > #board > :is(.gm-wrap, .rv-wrap) { position: relative; }
  body.in-room #boardPanel.rs-fit > #board > .gm-wrap > .gm-bar,
  body.in-room #boardPanel.rs-fit > #board > .rv-wrap > :is(.rv-score, .rv-slot) { position: absolute; top: calc(var(--rs-bar) + var(--rs-st) + 2 * var(--rs-gap)); right: calc(100% + 14px); width: var(--rs-col); margin: 0; z-index: 2; }
  body.in-room #boardPanel.rs-fit > #board > .gm-wrap > .gm-bar { min-height: 0; height: 52px; padding: 5px 5px 5px 10px; gap: 6px; }
  body.in-room #boardPanel.rs-fit > #board > .gm-wrap > .gm-bar .gm-bar-t { font-size: 12px; line-height: 1.15; -webkit-line-clamp: 3; line-clamp: 3; }
  body.in-room #boardPanel.rs-fit > #board > .gm-wrap > .gm-bar .gm-ok { padding-left: 10px; padding-right: 10px; }
  body.in-room #boardPanel.rs-fit > #board > .rv-wrap > .rv-score { gap: 6px; }
  body.in-room #boardPanel.rs-fit > #board > .rv-wrap > .rv-score .rv-pill { min-width: 0; flex: 1 1 0; padding: 4px 8px; }
  body.in-room #boardPanel.rs-fit > #board > .rv-wrap > .rv-slot { top: calc(var(--rs-bar) + var(--rs-st) + 3 * var(--rs-gap) + 42px); height: 28px; }
}
/* the narrow landscape column: a player bar too narrow for its whole second line keeps the colour dot and the first item
   (score / points) and leaves out the rest (level, "online"), instead of cutting every item to a few letters */
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room #boardPanel.rs-fit :is(#pTop, #pBottom).pbar { container-type: inline-size; }
}
@media (orientation: landscape) and (max-height: 500px) {
  @container (max-width: 190px) {
    body.in-room #boardPanel.rs-fit .pbar .pn small > span:not(.chip) ~ span { display: none; }
  }
}

/* ===== dortlu (Four in a Row), wave20: the board block sized by its real shape (7 x 6 holes in a frame), viewport only.
   Portrait: the frame's rim reaches into the 8 px page gutter, so the holes themselves get the full width (#board's
   width); block = drop row (1/7) + holes (6/7) + rims = width + 24 px. Phones held sideways (height-bound): no drop row
   (the dashed landing ring and the column highlight show the move), the frame takes the full height;
   block = 6/7 of the holes' width + rims. Tablets / desktop landscape are bound by the width and keep the drop row. ===== */
@media (max-width: 1080px) and (orientation: portrait) {
  body.in-room #boardPanel.rs-fit:has(#board .d4-wrap) { --board-ar: 1; --board-x: 24px; }
  body.in-room #boardPanel.rs-fit > #board > .d4-wrap > .d4-stage { padding-left: max(0px, calc(var(--d4-pad) - 8px)); padding-right: max(0px, calc(var(--d4-pad) - 8px)); }
}
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room #boardPanel.rs-fit:has(#board .d4-wrap) { --board-ar: .857143; --board-x: calc(8px + 16px / 7); }
  body.in-room #boardPanel.rs-fit > #board > .d4-wrap { --d4-pad: 8px; }
  body.in-room #boardPanel.rs-fit > #board > .d4-wrap > .d4-stage { padding-top: var(--d4-pad); }
  body.in-room #boardPanel.rs-fit > #board > .d4-wrap > .d4-stage > .d4-hand { display: none; }
  body.in-room #boardPanel.rs-fit > #board > .d4-wrap .d4-cols { top: calc(-1 * var(--d4-pad)); }
}

/* ---------- amiral (Battleship), v20: landscape side layout ----------
   Every landscape screen (phones held sideways, landscape tablets, desktop): the target sea is a square as tall as the
   board block (--rs-bh, from svh) on the right; the opponent's bar, a two-line status, the dock (your fleet's mini-map,
   the enemy fleet tracker, the weapon tray), your bar and the chat bar are in the column on its left. amiral.js reads
   #board's box and the dock's slot (.bsx-dock.side) once per window size and fits the seas into them; everything here
   depends on the viewport and the page kind only (never on game state, chat or the keyboard). Scoped to
   #boardPanel[data-game="amiral"]; Battleship is not in BO_FIT_GAMES, these rules mirror the FIT shell for it. */
@media (max-width: 960px) and (orientation: landscape) {
  body.in-room:has(#boardPanel[data-game="amiral"]) .topbar { position: fixed; top: calc(env(safe-area-inset-top, 0px) + var(--rs-pad)); left: calc(env(safe-area-inset-left, 0px) + 8px); width: var(--rs-bar); height: var(--rs-bar); padding: 0; gap: 0; border: 0; background: transparent; z-index: 40; }
  body.in-room:has(#boardPanel[data-game="amiral"]) .topbar > :not(#menuBtn) { display: none !important; }
  body.in-room:has(#boardPanel[data-game="amiral"]) .topbar #menuBtn { width: var(--rs-bar); height: var(--rs-bar); margin: 0; border-radius: 12px; background: var(--surface-2); }
  body.in-room .stage#boardPanel[data-game="amiral"] #pTop { margin-left: var(--rs-menu); width: auto; }
  body.in-room:has(#boardPanel[data-game="amiral"]) .content:has(> #gameArea.hidden) { padding-top: calc(var(--rs-pad) + var(--rs-menu)); }
  body.in-room:has(#boardPanel[data-game="amiral"]) .main > .langhint { margin-left: calc(8px + var(--rs-menu)); }
  /* the result card: the menu button steps aside while it is shown (as in portrait) */
  body.in-room:has(#boardPanel[data-game="amiral"] > #result.result:not(.hidden)) .topbar { visibility: hidden; }
}
@media (orientation: landscape) {
  body.in-room .stage#boardPanel[data-game="amiral"] {
    --am-bar: var(--rs-bar); --am-st: 32px; --am-cb: var(--rs-chat); --am-col: var(--rs-col);
    --rs-bh: calc(100svh - 2 * var(--rs-cpad) - 2 * var(--rs-spad));
    container-type: inline-size;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    column-gap: 14px; row-gap: var(--rs-gap); align-items: start; justify-items: stretch; min-height: 0;
    padding: var(--rs-spad);
  }
  body.in-room .stage#boardPanel[data-game="amiral"] > #pTopRow { display: contents; }
  body.in-room .stage#boardPanel[data-game="amiral"] #pTop { grid-column: 1; grid-row: 1; }
  body.in-room .stage#boardPanel[data-game="amiral"] > #status { grid-column: 1; grid-row: 2; }
  body.in-room .stage#boardPanel[data-game="amiral"] > #pBottom { grid-column: 1; grid-row: 4; align-self: end; }
  body.in-room .stage#boardPanel[data-game="amiral"] > #claimLine { grid-column: 1 / -1; }
  body.in-room .stage#boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) { grid-column: 1; grid-row: 5; position: relative; inset: auto; width: 100%; z-index: 26; }
  body.in-room .stage#boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) { background: transparent; box-shadow: none; }
  body.in-room .stage#boardPanel[data-game="amiral"] > .chat-bar .cb-field { background: var(--surface-2); border-color: transparent; }
  body.in-room .stage#boardPanel[data-game="amiral"] > #board { grid-column: 2; grid-row: 1 / -1; margin: 0; align-self: start; max-width: none; gap: 0; display: block;
    width: max(160px, min(calc(100cqw - var(--am-col) - 14px), var(--rs-bh))); height: var(--rs-bh); }
  body.in-room .stage#boardPanel[data-game="amiral"] > #board > .bsx { height: 100%; justify-content: center; }
  body.in-room .stage#boardPanel[data-game="amiral"] > #result.result { inset: 0; bottom: 0; }
  body.in-room .main:has(#boardPanel[data-game="amiral"]) .content { padding-top: var(--rs-cpad); padding-bottom: var(--rs-cpad); }
  /* the status: two fixed lines (amiral.js fits its texts into them) */
  body.in-room .stage#boardPanel[data-game="amiral"] > #status { height: var(--am-st); min-height: 0; max-height: none; padding: 0 2px; margin: 0; font-size: 13px; line-height: calc(var(--am-st) / 2);
    white-space: normal; text-align: left; justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
  /* the dock's slot: the column between the status line and your bar (+ the chat bar's row in rooms up to 1080 px) */
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-dock.side { position: absolute; right: calc(100% + 14px); width: calc(100cqw - 100% - 14px);
    top: calc(var(--am-bar) + var(--am-st) + 2 * var(--rs-gap)); bottom: calc(var(--am-bar) + var(--rs-gap) + var(--am-cb)); height: auto;
    display: flex; flex-direction: row; align-items: center; gap: 6px; margin: 0; }
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-dock.side.vert { flex-direction: column; align-items: stretch; justify-content: center; }
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-dock.side > .bsx-view.mini { align-self: center; }
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-dock.side > .bsx-dside { justify-content: center; align-self: stretch; }
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-dock.side.vert > .bsx-dside { flex: 0 0 auto; justify-content: flex-start; }
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-dock.side > .bsx-dside > .bsx-stats { flex: 0 1 auto; max-height: 100%; }
  /* four icon chips 2 x 2 (narrow columns) */
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-tray.compact.g2 { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
  body.in-room #boardPanel[data-game="amiral"] > #board .bsx-field { flex: none; }
}
/* phones held sideways: no frame, the smallest margins */
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room .main:has(#boardPanel[data-game="amiral"]) .content { padding-left: 8px; padding-right: 8px; }
  body.in-room .stage#boardPanel[data-game="amiral"] { border: 0; border-radius: 0; background: none; box-shadow: none; }
  body.in-room #boardPanel[data-game="amiral"] :is(#pTop, #pBottom).pbar { container-type: inline-size; }
}
/* landscape tablets and desktop: 56 px bars (turn = colour + dot), a 40 px two-line status */
@media (orientation: landscape) and (min-height: 501px) {
  body.in-room .stage#boardPanel[data-game="amiral"] { --am-bar: 56px; --am-st: 40px; --am-col: 200px; }
  body.in-room .stage#boardPanel[data-game="amiral"] :is(#pTop, #pBottom).pbar { min-height: 0; height: 56px; padding: 4px 12px 4px 6px; gap: 8px; border-radius: 14px; }
  body.in-room .stage#boardPanel[data-game="amiral"] :is(#pTop, #pBottom).pbar .pn b { font-size: 14px; gap: 6px; }
  body.in-room .stage#boardPanel[data-game="amiral"] :is(#pTop, #pBottom).pbar .psc { font-size: 22px; min-width: 18px; }
  body.in-room .stage#boardPanel[data-game="amiral"] :is(#pTop, #pBottom).pbar .ptag { font-size: 0; gap: 0; }
  body.in-room .stage#boardPanel[data-game="amiral"] :is(#pTop, #pBottom).pbar .ptag:not(.think)::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
  body.in-room .stage#boardPanel[data-game="amiral"] > #status { font-size: 14px; }
}
@media (orientation: landscape) and (min-height: 501px) and (max-width: 1080px) {
  body.in-room .main:has(#boardPanel[data-game="amiral"]) .content { padding-left: 16px; padding-right: 16px; }
  body.in-room .stage#boardPanel[data-game="amiral"] { border: 0; border-radius: 0; background: none; box-shadow: none; }
}
/* desktop: the stage keeps its card; no chat bar (the sidebar has the chat), the room may use a wide screen */
@media (min-width: 1081px) {
  body.in-room .stage#boardPanel[data-game="amiral"] { --am-cb: 0px; padding: 12px; }
  body.in-room .main:has(#boardPanel[data-game="amiral"]) .content { max-width: 1680px; padding-left: 24px; padding-right: 24px; }
  body.in-room .room-grid:has(> #boardPanel[data-game="amiral"]) { align-items: start; }
}
/* rooms on phones held sideways: the result card's veil ends above the chat bar (the bar stays over it, one tap away) */
@media (orientation: landscape) and (max-height: 500px) {
  body.in-room .stage#boardPanel[data-game="amiral"]:has(> #chatBar:not([hidden])) > #result.result { bottom: var(--am-cb); }
}

/* ===== wave20 shared shell ===== */
/* rooms on phones: the side card under the stage never peeks half into the first screen. The stage's grid row is at least
   one screen tall (svh, from layout only: nothing moves during play), so the card starts just below the fold; the stage
   keeps its own height (align-self: start), so its overlays (the result card's veil) are unchanged. Landscape: phones held
   sideways, where a wide board bound by the width leaves the stage shorter than the screen. */
@media (max-width: 960px) and (orientation: portrait), (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  body.in-room:not(.bot-room) .content.room > #gameArea.room-grid > #boardPanel { align-self: start; }
}
@media (max-width: 960px) and (orientation: portrait) {
  body.in-room:not(.bot-room) .content.room > #gameArea.room-grid:not(.hidden) { grid-template-rows: minmax(calc(100svh - var(--rs-pad) - 20px), auto) auto; row-gap: 20px; }
  /* wave20 fix: when the room card fits whole in the first screen (app.js fitSide(), from the layout only), it sits right
     under the stage, in the space a board bound by the width leaves; the rest of the page starts below the fold. On short
     phones only its button row is shown (.rs-side-mini: copy link, resign) when that fits; else the card stays below. */
  body.in-room:not(.bot-room) .content.room > #gameArea.room-grid.rs-side-in:not(.hidden) { grid-template-rows: auto auto; row-gap: 16px; align-content: start; min-height: calc(100svh - var(--rs-pad)); }
  body.in-room:not(.bot-room) .content.room > #gameArea.room-grid.rs-side-in.rs-side-mini:not(.hidden) { row-gap: 10px; }
  body.in-room:not(.bot-room) #gameArea.rs-side-mini > .side > .room-card { padding: 8px; }
  body.in-room:not(.bot-room) #gameArea.rs-side-mini > .side > .room-card > .rc-top { display: none; }
  body.in-room:not(.bot-room) #gameArea.rs-side-mini > .side > .room-card > .actions { margin-top: 0; }
}
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  body.in-room:not(.bot-room) .content.room > #gameArea.room-grid:not(.hidden) { grid-template-rows: minmax(calc(100svh - var(--rs-cpad) - 20px), auto) auto; row-gap: 20px; }
}
/* phones and small tablets held sideways (the shell's floating menu button): as in portrait, the button steps aside while
   the result card is shown, so it never covers the card's corner */
@media (max-width: 960px) and (orientation: landscape) {
  body.in-room:has(#boardPanel.rs-fit > #result.result:not(.hidden)) .topbar { visibility: hidden; }
}

/* wave20 fix: laptops (1081-1599 px wide): FIT boards are bound by the width there (side nav, the column of bars, the
   330 px chat card), so the board got nothing from the height it had. The chat card is 270 px, the column 200 px (as
   Battleship's), the gap 14 px and the page gutters 12 px: 1366x768 square boards 607 -> 718 px (the full --rs-bh),
   1280x720 521 -> 641 px. Viewport only.
   Later in wave20: the chat card 255 px and the column 186 px, so 1280x720 boards reach the full height too (641 -> 670). */
@media (min-width: 1081px) and (max-width: 1599px) {
  body.in-room { --rs-col: 186px; }
  body.in-room .content.room > .room-grid:has(> #boardPanel:is(.rs-fit, [data-game="amiral"])) { grid-template-columns: minmax(0, 1fr) 255px; gap: 14px; }
  body.in-room .main:has(#boardPanel:is(.rs-fit, [data-game="amiral"])) .content { padding-left: 12px; padding-right: 12px; }
  /* the narrower chat card: its eight reaction emoji in two even rows of four */
  body.in-room .room-grid:has(> #boardPanel:is(.rs-fit, [data-game="amiral"])) .chat-card .chat-react .rx-emo button { flex: 1 1 calc(25% - 4px); }
  /* vs-computer pages: the long "play <game> online" label wraps inside its button instead of overflowing the card */
  body.in-room .room-grid > .side .bot-online .btn { white-space: normal; height: auto; min-height: 44px; padding-top: 8px; padding-bottom: 8px; line-height: 1.2; text-align: center; }
}

/* wave20 fix: Backgammon on small phones held sideways (up to 700 px wide): its board is wider than tall and bound by the
   width there, so its column of bars is narrower (170 px, was 196): 568x320 board 326 -> 352 px wide. Viewport only. */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 700px) {
  body.in-room #boardPanel.rs-fit[data-game="tavla"] { --rs-col: 170px; }
  /* the chat bar's second row: [chat button][field] still side by side (44 + 6 + 120) */
  body.in-room #boardPanel.rs-fit[data-game="tavla"] > .chat-bar .cb-form { min-width: 0; }
}

/* wave20 fix: desktop rooms (>1080 px): the side column (room card + chat card) never runs below the first screen. It is
   as tall as the stage (stretched in the grid row), at least min(640 px, the screen) and at most one screen
   (100svh - the content's top / bottom padding); the chat card takes the rest under the room card and its message list is
   the flexible part (it shrinks and scrolls inside), so the head, the emoji / phrase rows and the input always show.
   1280x720: input bottom 747 -> 693 px; 1366x768 (Battleship): 770 -> 741. Viewport only, nothing moves during play. */
@media (min-width: 1081px) {
  body.in-room:not(.bot-room) .content.room > .room-grid > .side:has(> .chat-card) { align-self: stretch; min-height: min(640px, calc(100svh - 2 * var(--rs-cpad, 12px))); max-height: calc(100svh - 2 * var(--rs-cpad, 12px)); }
  body.in-room:not(.bot-room) .room-grid > .side > .room-card { flex: none; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card > .chat-head { flex: none; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card > .tabpane { flex: 1 1 0; min-height: 0; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card > #tab-chat:not(.hidden) { display: flex; flex-direction: column; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card > #tab-rules { overflow-y: auto; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card > #tab-chat > * { flex: none; }
  body.in-room:not(.bot-room) .room-grid > .side > .chat-card > #tab-chat > .chat-list { flex: 1 1 0; height: auto; min-height: 64px; }
}

/* ===== wave21 fix: landscape tablets (501 px or taller, up to 1080 px wide) =====
   1. The chat bar in the column (FIT games but Backgammon and Mangala, whose bars are wide; Battleship from 700 px tall) takes two
      rows, as on phones held sideways: [chat button][field] over a full-width emoji row (at least 4 whole emoji, 40-44 px,
      swipe for the rest). Its height is fixed (94 px; --rs-chat 100 px on the stage, so the column's overlays — chess trays,
      Gomoku's confirm bar, Reversi's pills, Battleship's dock, the Yut panel — keep clear of it): typing hides the emoji
      only visually, docking over the keyboard takes the bar out of its place, nothing else moves. While the result card is
      shown the emoji row steps aside (hidden, taps go through). The board is not touched (its width does not depend on
      the column's height). */
@media (orientation: landscape) and (min-height: 501px) and (max-width: 1080px) {
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]):has(> .chat-bar:not([hidden])) { --rs-chat: 100px; --yut-cb: 100px; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) { height: 94px; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) { flex-wrap: wrap; height: 94px; row-gap: 6px; align-content: flex-start; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-form { min-width: 0; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { flex: 0 0 100%; width: 100%; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx button { width: min(44px, 24%); }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx.cb-more { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 10px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 10px), transparent); }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar.typing:not([hidden]) > .cb-in:not(.float) > .cb-rx { display: flex; visibility: hidden; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .rx-cool { left: 0; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]),
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) { pointer-events: none; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) > :not(.cb-rx) { pointer-events: auto; }
  body.in-room #boardPanel.rs-fit:not([data-game="tavla"]):not([data-game="mangala"]):has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { visibility: hidden; }
}
@media (orientation: landscape) and (min-height: 700px) and (max-width: 1080px) {
  body.in-room #boardPanel[data-game="amiral"]:has(> .chat-bar:not([hidden])) { --rs-chat: 100px; }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) { height: 94px; }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) { flex-wrap: wrap; height: 94px; row-gap: 6px; align-content: flex-start; }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-form { min-width: 0; }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { flex: 0 0 100%; width: 100%; }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx button { width: min(44px, 24%); }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx.cb-more { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 10px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 10px), transparent); }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar.typing:not([hidden]) > .cb-in:not(.float) > .cb-rx { display: flex; visibility: hidden; }
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .rx-cool { left: 0; }
  body.in-room #boardPanel[data-game="amiral"]:has(> #result:not(.hidden)) > .chat-bar:not([hidden]),
  body.in-room #boardPanel[data-game="amiral"]:has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) { pointer-events: none; }
  body.in-room #boardPanel[data-game="amiral"]:has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) > :not(.cb-rx) { pointer-events: auto; }
  body.in-room #boardPanel[data-game="amiral"]:has(> #result:not(.hidden)) > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { visibility: hidden; }
}
/* Battleship below 700 px tall: its dock (your fleet's map) is bound by the column's height there, so the bar keeps one
   44 px row; when it is at least 300 px wide (the column beside a height-bound sea) the emoji part shows 4 whole 40 px emoji
   (swipe for the rest) and the field takes the rest. The bar is the container: its width comes from the layout only. */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 699px) and (max-width: 1080px) {
  body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) { container-type: inline-size; }
  @container (min-width: 300px) {
    body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-form { min-width: 0; }
    body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx { flex: none; width: 160px; }
    body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx button { width: 40px; }
    body.in-room #boardPanel[data-game="amiral"] > .chat-bar:not([hidden]) > .cb-in:not(.float) > .cb-rx.cb-more { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 8px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 8px), transparent); }
  }
}
/* 2. The player bars in the landscape column (tablets and desktop, 56 px): two lines. The name has the whole first line
      (from the avatar to the bar's right edge); the second line holds the colour dot / words, rating chips, the member
      mark and "you", with the turn dot and the score on its right. Words that do not fit are dropped by app.js (colour dot
      and presence dot stay). A bar narrower than 140 px (beside the floating menu button on small tablets) leaves out the
      avatar. Viewport only: the bars keep their 56 px. */
@media (orientation: landscape) and (min-height: 501px) {
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; grid-template-rows: 22px 22px; row-gap: 2px; align-content: center; container-type: inline-size; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .avatar { grid-column: 1; grid-row: 1 / 3; align-self: center; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn { grid-column: 2 / 5; grid-row: 1 / 3; display: grid; grid-template-columns: minmax(0, 1fr) auto auto 48px; grid-template-rows: 22px 22px; row-gap: 2px; column-gap: 5px; align-items: center; min-width: 0; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn > b { display: contents; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn > b > span:first-child { grid-column: 1 / -1; grid-row: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 22px; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn > b > .mmark { grid-column: 2; grid-row: 2; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn > b > em { grid-column: 3; grid-row: 2; line-height: 16px; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn > small { grid-column: 1; grid-row: 2; margin: 0; min-width: 0; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .ptag { grid-column: 3; grid-row: 2; align-self: center; }
  body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .psc { grid-column: 4; grid-row: 2; align-self: center; line-height: 22px; }
}
@media (orientation: landscape) and (min-height: 501px) {
  @container (max-width: 140px) {
    body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .avatar { display: none; }
    body.in-room .stage#boardPanel:is(.rs-fit, [data-game="amiral"]) :is(#pTop, #pBottom).pbar > .pn { grid-column: 1 / 5; }
  }
}
