/*
 * The board column, move list and engine analysis shared by the game page
 * (games/game_detail.html) and the game analyzer (games/game_analyzer.html).
 * The squares and pieces themselves: chess-board.css.
 */
/* Viewer: mobile first, the board at full width with the controls under
   it and the move list below; from 769px the move list sits beside a
   board of bounded size. */
.game-viewer {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-top: var(--spacing-md);
}
/* Shown by the script; the class display would override [hidden]. */
.game-viewer[hidden],
.game-side .alert[hidden],
.game-moves[hidden] {
    display: none;
}
.game-board-col {
    width: 100%;
    min-width: 0;
}
/* The board and the material strips above it: static/css/chess-board.css. */

.game-controls {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--spacing-xs);
    margin-top: var(--spacing-sm);
}
.game-controls .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0;
}
.game-controls svg {
    width: 20px;
    height: 20px;
}

.game-side {
    min-width: 0;
}
.game-side .alert {
    margin-bottom: var(--spacing-sm);
}
/* Move list: numbered pairs in a grid (number, White, Black), scrolling
   inside its own box. */
.game-moves {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    align-content: start;
    max-height: 320px;
    overflow-y: auto;
    margin: 0;
    padding: var(--spacing-xs);
    background: var(--color-card);
    border: 1px solid var(--color-border-light);
    border-radius: var(--border-radius-sm);
    font-variant-numeric: tabular-nums;
}
/* Phones: the whole list, with no scrolling box inside the scrolling page. */
@media (max-width: 768px) {
    .game-moves {
        max-height: none;
        overflow-y: visible;
    }
}
.game-move-number {
    padding: 6px var(--spacing-sm) 6px var(--spacing-xs);
    color: var(--color-text-lighter);
    text-align: right;
}
.game-move {
    padding: 6px var(--spacing-sm);
    border: none;
    border-radius: var(--border-radius-sm);
    background: none;
    font: inherit;
    font-weight: var(--font-weight-normal);
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
    /* The global button transition would fade the highlight in on every step. */
    transition: none;
}
.game-move:active { transform: none; }
.game-move:hover { background: var(--color-bg-light); }
.game-move:focus-visible { outline: 2px solid var(--color-primary); }
.game-move--current,
.game-move--current:hover {
    background: var(--color-primary);
    color: var(--color-text-on-primary);
}
.game-moves-result {
    grid-column: 1 / -1;
    padding: 6px var(--spacing-xs);
    font-weight: var(--font-weight-semibold);
    text-align: center;
}

/* Engine analysis (static/js/engine/analysis-ui.js). Marks use the
   design-system colours; on the highlighted move they take its text colour. */
.game-viewer {
    --mark-inaccuracy: var(--color-info);
    --mark-mistake: var(--color-warning);
    --mark-blunder: var(--color-danger);
}
.game-move-mark {
    margin-left: 3px;
    font-weight: var(--font-weight-semibold);
}
.game-move--inaccuracy .game-move-mark { color: var(--mark-inaccuracy); }
.game-move--mistake .game-move-mark { color: var(--mark-mistake); }
.game-move--blunder .game-move-mark { color: var(--mark-blunder); }
.game-move--current .game-move-mark { color: inherit; }

/* The evaluation bar: vertical, beside the board, at every width (on
   phones too, so the board gives up a little width instead of the page a
   row of height). White's share fills from White's side: the bottom, or
   the top when the board is flipped. */
.game-board-row {
    display: flex;
    align-items: stretch;
    gap: var(--spacing-xs);
}
.game-board-wrap {
    flex: 1 1 auto;
    min-width: 0;
}
/* Wide enough for '+4.3' or '-12' with some room on each side. */
.engine-bar {
    position: relative;
    flex: 0 0 30px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border);
    overflow: hidden;
    background: var(--board-eval-black);
}
.engine-bar[hidden] { display: none; }
.engine-bar-fill {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--white-share, 0.5) * 100%);
    background: var(--board-eval-white);
    transition: height 0.25s ease;
}
.engine-bar--flipped .engine-bar-fill { top: 0; bottom: auto; }
.engine-bar--pending .engine-bar-fill { opacity: 0.5; }
.engine-bar-label {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 4px;
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
    line-height: 1;
    text-align: center;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    color: var(--board-eval-black);
}
.engine-bar-label[data-side="black"] { top: 4px; bottom: auto; color: var(--board-eval-white); }
.engine-bar--flipped .engine-bar-label { top: 4px; bottom: auto; }
.engine-bar--flipped .engine-bar-label[data-side="black"] { top: auto; bottom: 4px; }
@media (max-width: 768px) {
    .engine-bar { flex-basis: 26px; }
}

.engine-panel {
    margin-top: var(--spacing-sm);
}
/* As tall as its buttons in every state, so the page does not move when
   they change ("Analysis complete" replaces them at the end). */
.engine-actions {
    min-height: 44px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-sm);
}
.engine-actions .btn {
    min-height: 44px;
    min-width: 44px;
}
/* Analyse: microscope; Resume (after Stop): play. */
#engine-analyse:not([data-mode="resume"]) .engine-icon-resume,
#engine-analyse[data-mode="resume"] .engine-icon-analyse { display: none; }
/* Phones: the (icon-only) buttons first, then the progress or the
   completion note; on desktop the note leads into the buttons on the right. */
@media (max-width: 768px) {
    .engine-actions .engine-progress { order: 1; }
}
.engine-actions [hidden],
.engine-chart[hidden] { display: none; }
/* Below the move list. */
.engine-chart {
    display: block;
    width: 100%;
    height: 96px;
    margin-top: var(--spacing-sm);
    border-radius: var(--border-radius-sm);
    background: var(--board-eval-black);
    cursor: pointer;
    touch-action: manipulation;
}
.engine-chart-area { fill: var(--board-eval-white); }
.engine-chart-line { fill: none; stroke: var(--board-eval-line); stroke-width: 1; }
.engine-chart-mid { stroke: var(--board-eval-mid); stroke-width: 1; stroke-dasharray: 3 3; }
.engine-chart-cursor { stroke: var(--color-primary); stroke-width: 2; }
.engine-chart-dot { stroke: var(--board-eval-white); stroke-width: 1; }
.engine-chart-dot--inaccuracy { fill: var(--mark-inaccuracy); }
.engine-chart-dot--mistake { fill: var(--mark-mistake); }
.engine-chart-dot--blunder { fill: var(--mark-blunder); }
.engine-credit { margin: var(--spacing-sm) 0 0; }

@media (min-width: 769px) {
    .game-viewer {
        flex-direction: row;
        align-items: flex-start;
    }
    .game-board-col {
        flex: 0 1 480px;
    }
    .game-side {
        flex: 1 1 220px;
    }
    .game-moves {
        max-height: 480px;
    }
}
