/*
 * The analysis board (games/_analysis_board.html), shared by the game page
 * (games/game_detail.html) and the game analyzer (games/_analyzer.html, in
 * the in-app and the public page).
 *
 * It builds on the board column of game-board.css: six controls (the last
 * opens the More menu), the engine area with the live lines, a move list
 * with variations, and the game page's own part (Back to the game).
 */
.board-controls {
    position: relative;
    grid-template-columns: repeat(6, 1fr);
}
.board-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 20;
    min-width: 220px;
    padding: var(--spacing-xs) 0;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-md);
}
.board-menu[hidden] { display: none; }
.board-menu-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    min-height: 44px;
    padding: 0 var(--spacing-md);
    border: none;
    border-radius: 0;
    background: none;
    font: inherit;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}
.board-menu-item[hidden] { display: none; }
.board-menu-item:hover,
.board-menu-item:focus-visible { background: var(--color-bg-light); outline: none; }
.board-menu-item:active { transform: none; }
.board-menu-item svg { width: 18px; height: 18px; flex: none; }
/* The engine switch: a small track that fills when on. */
.board-switch {
    position: relative;
    flex: none;
    width: 34px;
    height: 20px;
    margin-left: auto;
    border-radius: 10px;
    background: var(--color-border);
    transition: background 0.15s;
}
.board-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-card);
    transition: transform 0.15s;
}
[aria-checked="true"] > .board-switch { background: var(--color-primary); }
[aria-checked="true"] > .board-switch::after { transform: translateX(14px); }

/* Engine lines: on phones between the board and the controls, side by
   side at the top of the side column (moved by game-analyzer.js). Always
   three rows tall, so the controls never move. */
.board-engine { margin-top: var(--spacing-sm); }
.board-engine[hidden] { display: none; }
.board-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    min-height: 1.5em;
    color: var(--color-text-light);
}
.board-lines {
    list-style: none;
    margin: 2px 0 0;
    padding: 0;
}
.board-line {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    min-height: 32px;
    border-top: 1px solid var(--color-border-light);
    font-variant-numeric: tabular-nums;
}
.board-line-score {
    flex: none;
    min-width: 3.4em;
    padding: 1px 4px;
    border-radius: var(--border-radius-sm);
    font-weight: var(--font-weight-semibold);
    text-align: center;
    background: var(--board-eval-white);
    color: var(--board-eval-black);
}
.board-line-score[data-side="black"] {
    background: var(--board-eval-black);
    color: var(--board-eval-white);
}
.board-line-score:empty { visibility: hidden; }
.board-line-moves {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.board-line-number { color: var(--color-text-lighter); }
.board-pv-move {
    padding: 4px 3px;
    border: none;
    border-radius: var(--border-radius-sm);
    background: none;
    font: inherit;
    color: var(--color-text);
    cursor: pointer;
    transition: none;
}
.board-pv-move:hover { background: var(--color-bg-light); }
.board-pv-move:active { transform: none; }
.board-engine .alert { margin: var(--spacing-xs) 0 0; }
.board-engine .alert[hidden] { display: none; }

/* Move list: the game page's grid (static/css/game-board.css), one move
   number per row; each variation on its own full-width row, its moves
   flowing inline, nested ones in parentheses. */
.board-moves { min-height: 44px; }
.board-move-skip {
    padding: 6px var(--spacing-sm);
    color: var(--color-text-lighter);
}
.board-variation {
    grid-column: 1 / -1;
    margin: 2px 0 2px var(--spacing-md);
    padding: 2px 0 2px var(--spacing-sm);
    border-left: 2px solid var(--color-border-light);
    color: var(--color-text-light);
    line-height: 1.9;
}
.board-variation .game-move {
    display: inline;
    padding: 3px 5px;
    color: inherit;
}
.board-variation .game-move--current { color: var(--color-text-on-primary); }
.board-move-number {
    margin-left: 2px;
    color: var(--color-text-lighter);
}
.board-moves-empty { grid-column: 1 / -1; padding: 6px var(--spacing-xs); color: var(--color-text-lighter); }
/* Share (games/_analyzer_share_button.html): phones and tablets only; each
   page places it in its own header. On desktop the address bar already holds
   the link, so the button is not shown. */
.analyzer-share[hidden] { display: none; }
.analyzer-share svg { width: 18px; height: 18px; }
@media (min-width: 1025px) {
    .analyzer-share { display: none; }
}
@media (max-width: 768px) {
    .board-moves { max-height: none; overflow-y: visible; }
    /* Phones: the controls sit under the board, near the bottom of the
       screen and the tab bar, so the menu opens upwards, over the board. */
    .board-menu { top: auto; bottom: calc(100% + 4px); }
}
@media (min-width: 769px) {
    .board-moves { max-height: 480px; }
    .board-engine { margin-top: 0; margin-bottom: var(--spacing-sm); }
}

/* The game page (page='game'): the engine area is empty until Analyse, and
   adds no space of its own, so the page then looks as it did before the
   shared board. In analysis mode it holds the status and the live lines,
   with Back to the game beside the status in a variation. */
.board-engine--game {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: var(--spacing-sm);
    margin: 0;
}
.board-engine--game > * { grid-column: 1 / -1; }
.board-engine--game > .board-back { grid-column: 1; margin-top: var(--spacing-sm); }

.board-engine--game > .board-back:not([hidden]) ~ .board-status { grid-column: 2; margin-top: var(--spacing-sm); }
.board-engine--game > .board-status[hidden] { display: none; }
.board-back[hidden] { display: none; }
.board-back-button {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    min-height: 36px;
    white-space: nowrap;
}
.board-back-button svg { width: 16px; height: 16px; }
/* The status row is as tall as Back to the game, so the area keeps its
   height when a variation shows the button beside it. */
.board-engine--game > .board-status { min-height: 36px; margin-top: var(--spacing-sm); }
/* Phones: in analysis mode the area keeps its tallest height (game-page.js
   sets its min-height), so the controls below never move under a finger;
   its content stays at the top. */
@media (max-width: 768px) {
    .board-engine--tall { align-content: start; }
}
/* The opening of the position (placed by layout.js): right above the
   controls on phones, above the move list side by side. One row, kept even
   before the first move, so neither the controls nor the list ever move; a
   long name is cut (its full text is in the title). */
.board-opening {
    min-height: 1.5em;
    margin-top: var(--spacing-sm);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.board-opening-eco {
    font-weight: var(--font-weight-semibold);
    font-variant-numeric: tabular-nums;
}
@media (min-width: 769px) {
    .board-opening { margin: 0 0 var(--spacing-sm); }
}
/* Without a More menu (a locked game page), five controls. */
.board-controls:has(> [data-action="menu"][hidden]) { grid-template-columns: repeat(5, 1fr); }
.board-controls > [hidden] { display: none; }

@media (min-width: 769px) {
    /* With nothing to show (before Analyse), the empty grid would keep the
       credit's margin from collapsing and take 10px from the move list. */
    .engine-panel > .board-engine--game:not(:has(> :not([hidden]))) { display: none; }
}

/* Phones: the block under the board (status, Back to the game, the three
   lines, the opening) is condensed, so the board, the lines and the
   controls fit on the screen together: the text one pixel smaller, the
   lines and the status row lower, less space between them. */
@media (max-width: 768px) {
    .board-status,
    .board-lines,
    .board-opening { font-size: 13px; }
    .board-line { min-height: 26px; }
    .board-pv-move { padding: 2px 3px; }
    .board-line-score { padding: 0 4px; }
    .board-engine { margin-top: var(--spacing-xs); }
    .board-engine--game { margin-top: 0; }
    .board-engine--game > .board-status,
    .board-engine--game > .board-back:not([hidden]) ~ .board-status { min-height: 30px; margin-top: var(--spacing-xs); }
    .board-engine--game > .board-back { margin-top: var(--spacing-xs); }
    .board-back-button { min-height: 30px; }
    .board-opening { min-height: 1.4em; line-height: 1.4; margin-top: var(--spacing-xs); }
}
