.history {
    display: grid;
    grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr);
    gap: 1rem;
    padding: 1rem;
    box-sizing: border-box;
    height: 100%;
    min-height: 0;
}

/* ------------------------------- session tree ------------------------------- */

.history-tree {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 0.85rem;
    border: 1px solid rgb(128 128 128 / 0.28);
    border-radius: 12px;
    background: rgb(128 128 128 / 0.06);
}

.history-title {
    margin: 0 0 0.25rem;
    font-size: 1.2rem;
    line-height: 1.2;
}

.history-subtitle {
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.7;
}

.history-state {
    margin: 0.35rem 0;
    font-size: 0.9rem;
    opacity: 0.8;
}

.history-state--error {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    color: #e5484d;
}

.history-sessions {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.history-session {
    margin-bottom: 0.35rem;
}

.history-session-head {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    width: 100%;
    padding: 0.4rem 0.25rem;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.history-session-head:hover {
    background: rgb(128 128 128 / 0.1);
    border-radius: 8px;
}

.history-caret {
    width: 1rem;
    flex: none;
    opacity: 0.7;
}

.history-session-date {
    font-weight: 600;
}

.history-session-count {
    margin-left: auto;
    font-size: 0.78rem;
    opacity: 0.7;
}

.history-games {
    max-height: 24rem;
    overflow-y: auto;
    padding-left: 0.75rem;
}

.history-game {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    box-sizing: border-box;
    width: 100%;
    height: 84px;
    margin-bottom: 8px;
    padding: 0.5rem 0.6rem;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: 10px;
    background: rgb(128 128 128 / 0.08);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.history-game:hover {
    background: rgb(128 128 128 / 0.16);
}

.history-game.is-selected {
    border-color: #4c8dff;
    background: rgb(76 141 255 / 0.16);
}

.history-game-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.history-game-number {
    font-weight: 600;
}

.history-game-date {
    font-size: 0.78rem;
    opacity: 0.75;
    white-space: nowrap;
}

.history-game-settings {
    overflow: hidden;
    font-size: 0.76rem;
    opacity: 0.8;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.history-game-winners {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

.history-game-nowinner {
    font-size: 0.78rem;
    opacity: 0.6;
}

.history-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.history-chip-name {
    max-width: 8rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* --------------------------------- replay ---------------------------------- */

.history-replay {
    min-height: 0;
    overflow: auto;
}

.history-replay-pane {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    box-sizing: border-box;
    min-height: 100%;
    padding: 1rem;
    border: 1px solid rgb(128 128 128 / 0.28);
    border-radius: 12px;
    background: rgb(128 128 128 / 0.06);
    outline: none;
}

.history-replay-pane:focus-visible {
    outline: 2px solid #4c8dff;
    outline-offset: 2px;
}

.history-replay-meta {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin-top: 0.25rem;
}

.history-finish-reason {
    margin: 0.35rem 0 0;
    font-weight: 600;
}

.history-replay-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(12rem, 17rem);
    gap: 1rem;
    align-items: start;
}

.history-board {
    display: block;
    width: min(100%, 32rem);
    height: auto;
    max-height: 70vh;
    border: 1px solid rgb(128 128 128 / 0.3);
    border-radius: 12px;
    background: rgb(128 128 128 / 0.05);
}

/* Interior grid lines drawn by the board's own SVG. */
.history-board-line {
    stroke: currentColor;
    stroke-width: 2;
    opacity: 0.22;
}

.history-figure {
    display: inline-block;
    flex: none;
    vertical-align: middle;
}

/*
    A replay mark that appears as the viewer steps (a placement, or a Memory/Gravity change when stepping
    back) pops in; the transform origin is the figure's own 24×24 viewBox so the nested SVG scales around
    its centre. Reduced-motion users get the same board without the motion.
*/
@media (prefers-reduced-motion: no-preference) {
    .history-board__mark {
        transform-box: view-box;
        transform-origin: center;
        animation: history-mark-in 0.18s ease-out;
    }
}

@keyframes history-mark-in {
    from {
        opacity: 0;
        transform: scale(0.5);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .history-board__mark {
        animation: none;
    }
}

.history-avatar {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
}

/* -------------------------------- participants ------------------------------ */

.history-participant-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.history-participant {
    padding: 0.5rem 0.6rem;
    border: 1px solid rgb(128 128 128 / 0.28);
    border-radius: 10px;
    background: rgb(128 128 128 / 0.06);
}

.history-participant.is-winner {
    border-color: #4c8dff;
    background: rgb(76 141 255 / 0.14);
}

.history-participant-head {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.history-participant-name {
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.history-participant-scores {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    margin-top: 0.3rem;
    font-size: 0.78rem;
    opacity: 0.85;
}

/* -------------------------------- controls ---------------------------------- */

.history-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.history-button {
    padding: 0.4rem 0.7rem;
    border: 1px solid rgb(128 128 128 / 0.35);
    border-radius: 8px;
    background: rgb(128 128 128 / 0.1);
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.history-button:hover:not(:disabled) {
    background: rgb(128 128 128 / 0.2);
}

.history-button:disabled {
    opacity: 0.45;
    cursor: default;
}

.history-slider {
    flex: 1 1 10rem;
    min-width: 8rem;
}

.history-counter {
    min-width: 8rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.history-hint {
    margin: 0.25rem 0 0;
    font-size: 0.78rem;
    opacity: 0.7;
}

.history-hint--warning {
    color: #d9a900;
    opacity: 1;
}

/* --------------------------------- narrow ----------------------------------- */

@media (max-width: 60rem) {
    .history {
        grid-template-columns: 1fr;
    }

    .history-tree {
        max-height: 45vh;
    }

    .history-replay-body {
        grid-template-columns: 1fr;
    }
}
