/* Shared surrounding controls. Board geometry, wood, pits and stones are owned
   by the board styles. Online tables retain their existing tabbed panel. */
html[data-theme] #screen-game .material-game-bar__back,
html[data-theme] #screen-game #live-board-panel-toggle {
    align-items: center;
    justify-content: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--tp-material-edge);
    border-radius: var(--tp-control-radius);
    background: var(--tp-material-2);
    color: var(--tp-color-text);
    font-size: 16px;
    cursor: pointer;
}
html[data-theme] #screen-game .material-game-bar__back:not([hidden]) {
    display: inline-flex;
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
}
html[data-theme] #screen-game #game-live-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
}
html[data-theme] #screen-game #game-live-actions > .game-drawer-section__title {
    display: block;
    flex: 0 0 100%;
    margin: 0 0 4px;
    padding: 0;
    font-size: 12px;
    letter-spacing: .04em;
}
html[data-theme] #screen-game #game-live-actions > button:not([hidden]) {
    display: flex;
    flex: 1 1 72px;
    min-width: 0;
    min-height: 52px;
    height: auto;
    padding: 8px 4px;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
    line-height: 1.3;
}
html[data-theme] #screen-game #game-live-actions > button > i {
    color: inherit;
    opacity: 1;
    font-size: 16px;
}
html[data-theme] #screen-game #game-live-actions > button > span {
    white-space: normal;
    text-align: center;
}
html[data-theme] body:not(.online-game):not(.table-waiting-game) #screen-game #tab-history:not([hidden]) {
    display: flex !important;
    position: static;
    flex-direction: column;
    flex: 1 1 160px;
    min-height: 160px;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: none;
    margin: 0;
    transform: none;
    visibility: visible;
    opacity: 1;
    border: 1px solid var(--tp-material-edge);
    border-radius: var(--tp-radius-card);
    box-shadow: none;
}
html[data-theme] body:not(.online-game):not(.table-waiting-game) #screen-game #tab-history :is(.history-panel-close, .game-sheet-handle) {
    display: none;
}
html[data-theme] #screen-game #game-live-analysis:not([hidden]) { display: block !important; flex: 0 0 auto; }
html[data-theme] #screen-game :is(#game-live-actions, #tab-history, #game-live-analysis)[hidden] { display: none !important; }
html[data-theme] #game-menu-overlay .game-menu-item[hidden] { display: none !important; }
html[data-theme] #game-menu-overlay .modal-close-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--tp-material-edge);
    border-radius: var(--tp-control-radius);
    background: var(--tp-material-2);
    color: var(--tp-color-text);
}
html[data-theme] #screen-game :is(.material-game-bar__back, #live-board-panel-toggle):focus-visible {
    outline: 2px solid var(--tp-color-primary);
    outline-offset: 3px;
}
@media (max-width: 1099px) {
    html[data-theme] body:not(.online-game):not(.table-waiting-game) #screen-game #live-board-panel-toggle {
        display: inline-flex;
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        margin-inline-start: auto;
    }
    html[data-theme] body:not(.online-game):not(.table-waiting-game) #screen-game .material-game-logo { display: none; }
    html[data-theme] body:not(.online-game):not(.table-waiting-game) #screen-game #game-service-panel {
        display: flex;
        position: fixed;
        inset: 0 0 0 auto;
        z-index: 10012;
        grid-row: auto;
        flex-direction: column;
        gap: 16px;
        width: min(92vw, 360px) !important;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0 !important;
        padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
        border-radius: var(--tp-radius-panel) 0 0 var(--tp-radius-panel);
        overflow-y: auto;
        overscroll-behavior: contain;
        touch-action: pan-y;
        transform: translateX(100%);
        visibility: hidden;
        transition: transform var(--tp-motion-overlay) var(--tp-ease-drawer), visibility var(--tp-motion-overlay);
    }
    html[data-theme] body:not(.online-game):not(.table-waiting-game) #screen-game.side-panel-open #game-service-panel {
        transform: translateX(0);
        visibility: visible;
    }
    html[data-theme] #screen-game .game-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex: 0 0 auto;
        min-height: 44px;
        gap: 12px;
        padding: 0;
        margin: 0;
        color: var(--tp-color-text);
    }
    html[data-theme] #screen-game .game-drawer-head__copy strong { font-size: 17px; line-height: 1.25; }
    html[data-theme] #screen-game .game-drawer-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        min-height: 44px;
        flex: 0 0 44px;
        padding: 0;
        border: 1px solid var(--tp-material-edge);
        border-radius: var(--tp-control-radius);
        background: var(--tp-material-2);
        color: var(--tp-color-text);
        font-size: 16px;
        cursor: pointer;
    }
    html[data-theme] #screen-game .game-drawer-close:focus-visible { outline: 2px solid var(--tp-color-primary); outline-offset: 3px; }
    html[data-theme] #screen-game .game-side-panel-scrim:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 10011;
        background: rgba(30, 27, 23, .32);
    }
    html[data-theme] #screen-game .game-side-panel-scrim[hidden] { display: none; }
    html[data-theme] body.side-panel-locked { overflow: hidden; }
    html[data-theme] #screen-game .history-box { overflow-y: auto; max-height: 45dvh; }
}
@media (prefers-reduced-motion: reduce) {
    html[data-theme] #screen-game #game-service-panel { transition: none; }
}
html[data-input="keyboard"] #screen-game #game-service-panel { transition: none !important; }

/* ---------------------------------------------------------------------------
   Mobile game screen: stack from the top, let the board use the freed height,
   and keep Undo / Resign / History / Menu in reach under the player card.
   --------------------------------------------------------------------------- */
.game-mobile-actions { display: none; }

@media (max-width: 600px) {
    body.game-active #screen-game.active {
        --game-bar-offset: max(8px, calc(env(safe-area-inset-top, 0px) + 4px));
        grid-template-rows: calc(var(--game-bar-offset) + 58px) auto auto minmax(0, 1fr) auto auto !important;
        align-content: stretch !important;
        row-gap: 2px;
    }
    body.game-active #screen-game.active::before { min-height: 0; }
    body.game-active #screen-game.active .match-player { flex: 0 0 auto; }
    body.game-active #screen-game.active #tab-board { min-height: 0; }
    body.game-active #screen-game.active .board-stage .board-layout {
        aspect-ratio: auto !important;
        height: 100% !important;
        min-height: 300px;
        /* Pits grow taller, but not into thin slots on tall phones. */
        max-height: calc((100vw - 4px) * 1.45) !important;
    }

    #screen-game .game-mobile-actions {
        grid-column: 1;
        margin-inline: 2px;
        grid-row: 6;
        display: flex;
        gap: 8px;
        width: calc(100vw - 4px);
        padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
    }
    #screen-game .game-mobile-action:not([hidden]) {
        display: flex;
        flex: 1 1 0;
        min-width: 0;
        min-height: 48px;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 4px 2px;
        border: 1px solid var(--border-subtle);
        border-radius: var(--tp-control-radius, 12px);
        background: var(--surface-2);
        color: var(--text-primary);
        font: inherit;
        font-size: 11px;
        font-weight: 600;
        line-height: 1.1;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: transform .12s ease, background-color .12s ease;
    }
    #screen-game .game-mobile-action > i { font-size: 16px; }
    #screen-game .game-mobile-action > span {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #screen-game .game-mobile-action--danger { color: var(--danger); }
    #screen-game .game-mobile-action:disabled { opacity: .45; cursor: default; }
    #screen-game .game-mobile-action:not(:disabled):active { transform: scale(.96); }
    #screen-game .game-mobile-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
}
@media (max-width: 600px) and (prefers-reduced-motion: reduce) {
    #screen-game .game-mobile-action { transition: none; }
    #screen-game .game-mobile-action:not(:disabled):active { transform: none; }
}

/* Kazan score: the most important number on the screen, with a progress rail
   toward the 82 stones that win the game (--kazan-progress is set by board.js). */
@media (max-width: 600px) {
    body.game-active #screen-game .board-container {
        grid-template-rows: minmax(0, 1fr) auto 44px 3px 44px auto minmax(0, 1fr) !important;
    }
    body.game-active #screen-game .kazan-track {
        padding-bottom: 8px !important;
    }
    body.game-active #screen-game .kazan-track .kazan-score {
        min-width: 44px !important;
        padding: 0 6px !important;
        font-size: 26px !important;
        font-weight: 700 !important;
        font-variant-numeric: tabular-nums;
        line-height: 1.1 !important;
    }
    body.game-active #screen-game .kazan-track::before,
    body.game-active #screen-game .kazan-track::after {
        content: '';
        position: absolute;
        pointer-events: none;
    }
    body.game-active #screen-game .kazan-track::before {
        left: 5px;
        right: 8px;
        bottom: 2px;
        height: 3px;
        border-radius: 2px;
        background:
            linear-gradient(var(--accent) 0 0) left / calc(var(--kazan-progress, 0) * 100%) 100% no-repeat,
            color-mix(in srgb, currentColor 16%, transparent);
        transition: background-size .35s ease;
    }
    body.game-active #screen-game .kazan-track::after {
        right: 6px;
        bottom: 1px;
        width: 2px;
        height: 6px;
        border-radius: 1px;
        background: var(--success);
        opacity: .8;
    }
}
@media (max-width: 600px) and (prefers-reduced-motion: reduce) {
    body.game-active #screen-game .kazan-track::before { transition: none; }
}

/* Untimed games have no clock to show, so drop the button-like placeholder. */
@media (max-width: 600px) {
    body.untimed-game #screen-game .match-clock { display: none !important; }
}

/* Kazan lead: "+N" beside the player who is ahead. */
.match-lead-badge { display: none; }
@media (max-width: 600px) {
    #screen-game .match-lead-badge:not([hidden]) {
        display: inline-flex;
        align-items: center;
        flex: 0 0 auto;
        padding: 2px 7px;
        border-radius: 999px;
        background: color-mix(in srgb, var(--success) 18%, transparent);
        color: var(--success);
        font-size: 12px;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        line-height: 1.2;
    }
}

/* ── Карточка результата: одно главное действие и сводка в одну строку ──
   Прежде семь равных кнопок и таблица из трёх ячеек. Теперь: «Разобрать партию»
   крупно, «Сыграть ещё» и «Домой» рядом, остальное за «Ещё». Правила несут
   префикс карточки и !important, потому что glass-system и milestone красят эти
   же узлы с !important и тремя идентификаторами в селекторе. */
html[data-theme] #end-screen .match-result-card .match-result-actions {
    gap: 8px !important;
}
html[data-theme] #end-screen .match-result-card .match-result-actions .match-result-action {
    min-height: 48px;
    font-size: 14px !important;
    transition: transform var(--tp-motion-press) var(--tp-ease-out), background-color var(--tp-motion-base, 220ms) var(--tp-ease-out);
}
html[data-theme] #end-screen .match-result-card .match-result-actions .match-result-action:active:not(:disabled) {
    transform: scale(0.97);
}
html[data-theme] #end-screen .match-result-card .match-result-actions #btn-end-review {
    grid-column: 1 / -1;
    min-height: 54px !important;
    font-size: 16px !important;
    font-weight: 800 !important;
    background: var(--tp-color-primary) !important;
    color: var(--tp-color-primary-ink) !important;
    border-color: var(--tp-color-primary) !important;
}
/* Пока запись сохраняется, главная кнопка остаётся главной, только притихшей. */
html[data-theme] #end-screen .match-result-card .match-result-actions #btn-end-review:disabled {
    opacity: 0.55;
}
/* «Сыграть ещё» больше не перехватывает акцент, пока разбор недоступен. */
html[data-theme] #end-screen .match-result-card .match-result-actions:has(#btn-end-review:disabled) #btn-end-rematch.match-result-action,
html[data-theme] #end-screen .match-result-card .match-result-actions #btn-end-rematch.match-result-action,
html[data-theme] #end-screen .match-result-card .match-result-actions #btn-end-menu.match-result-action {
    background: var(--tp-color-surface-raised) !important;
    color: var(--tp-color-text) !important;
    border-color: var(--tp-color-border) !important;
}
html[data-theme] #end-screen .match-result-card .match-result-actions:has(#btn-end-rematch[hidden]) #btn-end-menu {
    grid-column: 1 / -1;
}

/* Сводка: причина · время · ходы — тише счёта. */
html[data-theme] #end-screen .match-result-card .match-result-details {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 2px 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible;
    border: 0 !important;
    border-radius: 0 !important;
    background: none !important;
    color: var(--tp-color-text-muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
html[data-theme] #end-screen .match-result-card .match-result-details > div {
    display: inline-flex;
    gap: 6px;
    padding: 0 !important;
    background: none !important;
    grid-column: auto !important;
}
html[data-theme] #end-screen .match-result-card .match-result-details > div + div::before {
    content: '·';
    margin: 0 0 0 6px;
    color: var(--tp-color-text-muted);
}
html[data-theme] #end-screen .match-result-card .match-result-details dd {
    margin: 0 !important;
    color: var(--tp-color-text-muted) !important;
    font-size: 13px;
    font-weight: 600 !important;
}
/* Подпись остаётся для чтения с экрана; на виду только у числа ходов. */
html[data-theme] #end-screen .match-result-card .match-result-details dt {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
html[data-theme] #end-screen .match-result-card .match-result-details > div:nth-child(3) dt {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    order: 2;
    margin: 0;
    font-size: 13px !important;
    letter-spacing: 0;
    text-transform: lowercase;
}
/* Крупное изменение рейтинга уже сказано героем — строка его не повторяет. */
html[data-theme] #end-screen .match-result-card .match-rating-hero:not([hidden]) ~ .match-result-details #end-rating-row {
    display: none !important;
}

/* Итог разбора: тот же ответ, что в полном разборе, только сверху. */
.match-insight {
    width: 100%;
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--tp-color-border);
    border-radius: var(--tp-radius-sm, 12px);
    background: var(--tp-color-surface-raised);
    color: var(--tp-color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform var(--tp-motion-press) var(--tp-ease-out);
}
.match-insight:not([data-state="hidden"]) {
    display: flex;
}
.match-insight:disabled {
    cursor: default;
}
.match-insight[data-state="ready"]:active {
    transform: scale(0.985);
}
.match-insight[data-state="ready"] > * {
    animation: match-insight-in var(--tp-motion-overlay, 220ms) var(--tp-ease-out) both;
}
.match-insight__loading {
    display: block;
    padding: 14px 0;
    color: var(--tp-color-text-muted);
    font-size: 13px;
    text-align: center;
    animation: match-insight-pulse 1.4s var(--tp-ease-in-out) infinite;
}
.match-insight__side {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 2px 10px;
}
.match-insight__name {
    min-width: 0;
    overflow: hidden;
    color: var(--tp-color-text-muted);
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.match-insight__accuracy {
    grid-row: 1;
    grid-column: 2;
    color: var(--tp-color-text);
    font-size: 20px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.match-insight__counts {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.match-insight__count {
    min-width: 32px;
    padding: 1px 6px;
    border-radius: var(--tp-radius-pill, 999px);
    background: color-mix(in srgb, var(--chip) 14%, transparent);
    color: var(--chip);
    font-size: 11px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.match-insight__count[data-quality="weak"] { --chip: var(--tp-color-warning); }
.match-insight__count[data-quality="mistake"] { --chip: color-mix(in srgb, var(--tp-color-warning) 45%, var(--tp-color-danger)); }
.match-insight__count[data-quality="blunder"] { --chip: var(--tp-color-danger); }
.match-insight__count[data-zero] {
    background: none;
    color: var(--tp-color-text-muted);
    opacity: 0.7;
}
.match-insight__spark {
    width: 100%;
    height: 28px;
    overflow: visible;
}
.match-insight__zero {
    stroke: var(--tp-color-border);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}
.match-insight__line {
    fill: none;
    stroke: var(--tp-color-primary);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}
/* Стороны стоят рядом, как в строке игроков; график идёт под ними. */
.match-insight[data-state="ready"] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 16px;
}
.match-insight__spark { grid-column: 1 / -1; }
@media (max-width: 419px) {
    html[data-theme] #end-screen .match-result-card .match-result-actions > #btn-end-rematch > i,
    html[data-theme] #end-screen .match-result-card .match-result-actions > #btn-end-menu > i { display: none; }
    html[data-theme] #end-screen .match-result-card .match-result-actions > .match-result-action:not(#btn-end-review) {
        font-size: 13px !important;
        padding: 6px 8px !important;
    }
}

/* «Ещё»: второстепенные действия за одним касанием. */
html[data-theme] #end-screen .match-result-card .match-result-more {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
html[data-theme] #end-screen .match-result-card .match-result-more[hidden] { display: none !important; }
.match-result-more__toggle {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 16px;
    border: 0;
    border-radius: var(--tp-radius-sm, 12px);
    background: none;
    color: var(--tp-color-text-muted);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--tp-motion-press) var(--tp-ease-out), color var(--tp-motion-base, 220ms) var(--tp-ease-out);
}
.match-result-more__toggle:active { transform: scale(0.97); }
.match-result-more__toggle i {
    font-size: 11px;
    transition: transform var(--tp-motion-overlay, 220ms) var(--tp-ease-out);
}
.match-result-more.is-open .match-result-more__toggle i { transform: rotate(180deg); }
.match-result-more__toggle:focus-visible {
    outline: 2px solid var(--tp-color-focus, var(--tp-color-primary));
    outline-offset: 2px;
}
.match-result-more__panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    animation: match-insight-in var(--tp-motion-overlay, 220ms) var(--tp-ease-out) both;
}
.match-result-more__panel[hidden] { display: none; }
html[data-theme] #end-screen .match-result-card .match-result-more__panel .match-result-action {
    min-height: 44px !important;
    font-size: 13px !important;
}
@media (hover: hover) {
    .match-result-more__toggle:hover { color: var(--tp-color-text); }
}

@keyframes match-insight-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}
@keyframes match-insight-pulse {
    50% { opacity: 0.5; }
}
@media (max-height: 700px) {
    html[data-theme] #end-screen .match-result-card .match-result-ornament { display: none; }
    html[data-theme] #end-screen .match-result-card { gap: 6px !important; padding-top: 20px !important; }
}
@media (prefers-reduced-motion: reduce) {
    .match-insight, .match-insight > *, .match-insight__loading,
    .match-result-more__panel, .match-result-more__toggle, .match-result-more__toggle i {
        animation: none !important;
        transition: none !important;
    }
}

/* ==========================================================================
   Mobile compaction: Puzzles list, AI game setup, Profile header.
   Colours come from the shared tokens so every theme follows.
   ========================================================================== */

/* ── Puzzles (<= 900px): continue card + collapsible groups of numbered cells ── */
@media (max-width: 900px) {
    #screen-puzzles .tp-puzzle-continue {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
        width: 100%;
        min-height: 76px;
        padding: 14px 16px;
        border: 0;
        border-radius: 16px;
        background: var(--tp-color-primary);
        color: var(--tp-color-primary-ink);
        font: inherit;
        text-align: left;
        cursor: pointer;
        box-shadow: var(--tp-shadow-sm);
        transition: transform var(--tp-motion-press) var(--tp-ease-out);
    }
    #screen-puzzles .tp-puzzle-continue:active { transform: scale(0.98); }
    #screen-puzzles .tp-puzzle-continue__copy { min-width: 0; display: grid; gap: 2px; }
    #screen-puzzles .tp-puzzle-continue__copy small { font-size: 12px; font-weight: 650; opacity: 0.8; }
    #screen-puzzles .tp-puzzle-continue__copy strong { font-size: 19px; font-weight: 750; line-height: 1.15; font-variant-numeric: tabular-nums; }
    #screen-puzzles .tp-puzzle-continue__copy span {
        overflow: hidden; font-size: 13px; line-height: 1.3; opacity: 0.88;
        text-overflow: ellipsis; white-space: nowrap;
    }
    #screen-puzzles .tp-puzzle-continue__action {
        display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
        border-radius: 999px; background: var(--tp-color-primary-ink); color: var(--tp-color-primary);
        font-size: 14px; font-weight: 700; white-space: nowrap;
    }
    #screen-puzzles .tp-puzzle-continue:focus-visible,
    #screen-puzzles .tp-puzzle-group__head:focus-visible,
    #screen-puzzles .tp-puzzle-cell:focus-visible { outline: 2px solid var(--tp-color-primary); outline-offset: 2px; }

    /* The daily card keeps its action but stops being a second hero. */
    #screen-puzzles #daily-puzzle-card { min-height: 0; padding: 12px 14px; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
    #screen-puzzles #daily-puzzle-card .tp-puzzle-daily__icon { width: 36px; height: 36px; border-radius: 10px; font-size: 15px; }
    #screen-puzzles #daily-puzzle-card .tp-puzzle-daily__copy { gap: 2px; }
    #screen-puzzles #daily-puzzle-card .tp-puzzle-daily__copy strong { font-size: 15px; }
    #screen-puzzles #daily-puzzle-card .tp-puzzle-daily__copy span {
        display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; overflow: hidden; font-size: 12px;
    }
    #screen-puzzles #daily-puzzle-card .tp-puzzle-daily__action { grid-column: auto; justify-self: end; }
    #screen-puzzles .tp-puzzle-campaign { margin-top: 18px; }
    #screen-puzzles .tp-puzzle-campaign .tp-section-heading { margin-bottom: 8px; }

    #screen-puzzles .tp-puzzle-grid--grouped { display: block; }
    html[data-theme] body:not(.game-active) #screen-puzzles #puzzles-grid > .tp-puzzle-groups {
        display: grid; gap: 8px; padding: 0;
        border: 0 !important; border-radius: 0 !important; background: none !important; box-shadow: none !important;
    }
    #screen-puzzles .tp-puzzle-group {
        border: 1px solid var(--tp-color-border); border-radius: 14px; background: var(--tp-color-surface); overflow: hidden;
    }
    #screen-puzzles .tp-puzzle-group__head {
        display: grid; grid-template-columns: minmax(0, 1fr) auto 16px; align-items: center; column-gap: 10px; row-gap: 9px;
        width: 100%; min-height: 52px; padding: 12px 14px; border: 0; background: transparent;
        color: var(--tp-color-text); font: inherit; text-align: left; cursor: pointer;
        transition: background-color var(--tp-motion-fast) var(--tp-ease-out);
    }
    #screen-puzzles .tp-puzzle-group__head:active { background: var(--tp-color-surface-raised); }
    #screen-puzzles .tp-puzzle-group__label { font-size: 15px; font-weight: 700; }
    #screen-puzzles .tp-puzzle-group__count { font-size: 13px; font-weight: 700; color: var(--tp-color-text-secondary); font-variant-numeric: tabular-nums; }
    #screen-puzzles .tp-puzzle-group__chevron {
        justify-self: end; font-size: 12px; color: var(--tp-color-text-muted);
        transition: transform var(--tp-motion-base) var(--tp-ease-out);
    }
    #screen-puzzles .tp-puzzle-group__head[aria-expanded="true"] .tp-puzzle-group__chevron { transform: rotate(180deg); }
    #screen-puzzles .tp-puzzle-group__bar {
        grid-column: 1 / -1; height: 4px; border-radius: 999px; overflow: hidden;
        background: color-mix(in srgb, var(--tp-color-text) 12%, transparent);
    }
    #screen-puzzles .tp-puzzle-group__bar > span { display: block; height: 100%; border-radius: inherit; background: var(--tp-color-success); }
    #screen-puzzles .tp-puzzle-group__grid {
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; padding: 2px 12px 12px;
    }
    #screen-puzzles .tp-puzzle-group__grid[hidden] { display: none; }
    #screen-puzzles .tp-puzzle-cell {
        position: relative; display: grid; place-items: center; min-width: 44px; min-height: 48px; padding: 0;
        border: 1px solid var(--tp-color-border); border-radius: 12px; background: var(--tp-color-surface-raised);
        color: var(--tp-color-text); font: 700 16px/1 var(--tp-font-sans, inherit); font-variant-numeric: tabular-nums;
        cursor: pointer; transition: transform var(--tp-motion-press) var(--tp-ease-out);
    }
    #screen-puzzles .tp-puzzle-cell:active:not(:disabled) { transform: scale(0.95); }
    #screen-puzzles .tp-puzzle-cell i { position: absolute; top: 4px; right: 5px; font-size: 9px; line-height: 1; }
    #screen-puzzles .tp-puzzle-cell.is-solved {
        border-color: color-mix(in srgb, var(--tp-color-success) 45%, var(--tp-color-border));
        background: color-mix(in srgb, var(--tp-color-success) 14%, var(--tp-color-surface));
    }
    #screen-puzzles .tp-puzzle-cell.is-solved i { color: var(--tp-color-success); }
    #screen-puzzles .tp-puzzle-cell.is-next {
        border-color: var(--tp-color-primary);
        background: color-mix(in srgb, var(--tp-color-primary) 18%, var(--tp-color-surface));
        box-shadow: inset 0 0 0 1px var(--tp-color-primary);
    }
    #screen-puzzles .tp-puzzle-cell:disabled { cursor: not-allowed; opacity: 0.5; }
    #screen-puzzles .tp-puzzle-cell:disabled i { color: var(--tp-color-text-muted); }
}

/* ── AI game setup (<= 600px): segmented rows, level chips, pinned start ── */
.ai-setup-summary { display: none; }
@media (max-width: 600px) {
    html[data-theme] #screen-bot-setup .ai-setup-page-heading p { display: none; }
    html[data-theme] #screen-bot-setup .ai-trainer-section-heading {
        position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; font-size: 12px;
    }
    html[data-theme] #screen-bot-setup .ai-trainer-section-heading > span { font-size: 12px; }
    html[data-theme] #screen-bot-setup .ai-setup-config { padding: 12px; }
    html[data-theme] #screen-bot-setup .ai-setup-fieldset { margin-bottom: 12px; }
    html[data-theme] #screen-bot-setup .ai-setup-fieldset legend { margin-bottom: 6px; font-size: 12px; letter-spacing: 0.04em; }
    html[data-theme] #screen-bot-setup .ai-segmented { padding: 3px; gap: 3px; border-radius: 14px; }
    html[data-theme] #screen-bot-setup .ai-segment-option { min-height: 44px; padding-inline: 6px; font-size: 13px; font-weight: 650; gap: 6px; }

    html[data-theme] #screen-bot-setup .ai-difficulty-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
    html[data-theme] #screen-bot-setup .ai-difficulty-grid .ai-choice-card[data-ai-level] {
        position: relative; display: flex !important; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; min-height: 56px; padding: 8px 4px 6px; text-align: center; border-radius: 12px;
    }
    /* The level's portrait sits above its number, round like a messenger avatar. */
    html[data-theme] #screen-bot-setup .ai-difficulty-grid .ai-choice-card[data-ai-level]::before {
        --ai-face-size: 44px; margin-bottom: 4px; flex: 0 0 auto;
    }
    html[data-theme] #screen-bot-setup .ai-choice-card__level { font-size: 16px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
    html[data-theme] #screen-bot-setup .ai-choice-card__level > [data-i18n] { display: none; }
    html[data-theme] #screen-bot-setup .ai-difficulty-grid .ai-choice-card strong {
        max-width: 100%; font-size: 12px; font-weight: 650; line-height: 1.15; overflow-wrap: anywhere;
    }
    /* Badge text stays for assistive tech; the chip shows a lock instead. */
    html[data-theme] #screen-bot-setup .ai-choice-card__badge {
        position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; white-space: nowrap; font-size: 12px;
    }
    html[data-theme] #screen-bot-setup .ai-choice-card[data-guest-locked]::after,
    html[data-theme] #screen-bot-setup .ai-choice-card.is-coming-soon::after {
        content: '\f023'; position: absolute; top: 5px; right: 6px;
        color: var(--tp-color-text-muted); font: 900 11px/1 'Font Awesome 6 Free';
    }
    html[data-theme] #screen-bot-setup .ai-guest-level-note,
    html[data-theme] #screen-bot-setup .ai-coming-soon-hint { min-height: 0; margin-top: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.4; }

    html[data-theme] #screen-bot-setup .ai-setup-details { margin-top: 6px; }
    html[data-theme] #screen-bot-setup .ai-setup-details > summary {
        display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 2px;
        color: var(--tp-color-text-secondary); font-size: 13px; font-weight: 650; cursor: pointer; list-style: none;
    }
    html[data-theme] #screen-bot-setup .ai-setup-details > summary::-webkit-details-marker { display: none; }
    html[data-theme] #screen-bot-setup .ai-setup-details > summary::after {
        content: '\f078'; font: 900 11px/1 'Font Awesome 6 Free';
        transition: transform var(--tp-motion-base) var(--tp-ease-out);
    }
    html[data-theme] #screen-bot-setup .ai-setup-details[open] > summary::after { transform: rotate(180deg); }
    html[data-theme] #screen-bot-setup .ai-setup-details > p { margin: 0 0 8px; font-size: 12px; line-height: 1.45; }

    html[data-theme] #screen-bot-setup .ai-time-grid { gap: 6px; }
    html[data-theme] #screen-bot-setup .ai-time-grid .ai-choice-card {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        min-height: 52px; padding: 6px 4px; text-align: center; border-radius: 12px;
    }
    html[data-theme] #screen-bot-setup .ai-time-card strong { font-size: 16px; font-variant-numeric: tabular-nums; }
    html[data-theme] #screen-bot-setup .ai-time-card span { font-size: 12px; }

    /* Opponent card collapses to its one reassuring line; the summary above
       the start button carries side / level / time. */
    html[data-theme] #screen-bot-setup .ai-setup-preview {
        padding: 0 4px; border: 0 !important; background: none !important; box-shadow: none !important;
    }
    html[data-theme] #screen-bot-setup .ai-setup-preview .ai-opponent-heading,
    html[data-theme] #screen-bot-setup .ai-setup-preview dl { display: none; }
    html[data-theme] #screen-bot-setup .ai-setup-preview p { margin: 0; font-size: 12px; text-align: center; }

    html[data-theme] #screen-bot-setup .ai-setup-shell { padding-bottom: calc(190px + env(safe-area-inset-bottom, 0px)); }
    html[data-theme] #screen-bot-setup .ai-setup-cta-wrap {
        display: grid; gap: 6px; padding: 8px 10px 10px;
        border: 1px solid var(--tp-color-border); border-radius: 18px;
        background: var(--tp-color-surface); box-shadow: var(--tp-shadow-sm);
    }
    html[data-theme] #screen-bot-setup .ai-setup-summary {
        display: block; margin: 0; overflow: hidden; color: var(--tp-color-text-secondary);
        font-size: 13px; font-weight: 650; line-height: 1.3; text-align: center; text-overflow: ellipsis; white-space: nowrap;
    }
    html[data-theme] #screen-bot-setup .ai-start-button { min-height: 48px !important; }
}

/* ── Profile header: collapse the empty cover band, compact counters ── */
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .profile-identity-card { position: relative; }
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .profile-identity-card.has-no-cover { padding-top: 18px; }
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover { display: contents; }
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-avatar-wrap { margin-top: 0; }
/* The upload action stays reachable as a quiet pill in the card corner. */
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover-control {
    position: absolute; top: 8px; right: 8px; min-height: 36px; padding: 0 12px;
    border: 1px solid var(--tp-color-border); background: transparent; backdrop-filter: none;
    color: var(--tp-color-text-secondary);
    transition: background-color var(--tp-motion-fast) var(--tp-ease-out), transform var(--tp-motion-press) var(--tp-ease-out);
}
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover-control::after { content: ''; position: absolute; inset: -4px; }
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover-control:hover { background: var(--tp-color-surface-raised); }
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover-control:active { transform: scale(0.96); }
html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover-control:focus-within { outline: 2px solid var(--tp-color-primary); outline-offset: 2px; }

@media (max-width: 720px) {
    /* Counters become three equal stat chips: number over label. */
    #screen-profile.profile-unified .profile-social-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; width: 100%; margin-top: 8px; }
    #screen-profile.profile-unified .profile-social-row .profile-friend-action { grid-column: 1 / -1; justify-content: center; min-height: 44px; }
    #screen-profile.profile-unified .profile-social-row .profile-friends-count {
        flex-direction: column; justify-content: center; gap: 2px; min-height: 52px; padding: 6px 4px; border-radius: 12px; text-align: center;
    }
    #screen-profile.profile-unified .profile-social-row .profile-friends-count > i { display: none; }
    #screen-profile.profile-unified .profile-social-row .profile-friends-count strong { font-size: 17px; line-height: 1.1; }
    #screen-profile.profile-unified .profile-social-row .profile-friends-count span { font-size: 12px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }

    /* Without a cover the avatar sits beside name and rating. */
    html[data-theme] body:not(.game-active) #screen-profile.profile-unified .profile-identity-card.has-no-cover {
        grid-template-columns: 72px minmax(0, 1fr); column-gap: 14px; row-gap: 4px; padding: 14px; align-items: center; justify-items: stretch;
    }
    html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-avatar-wrap,
    html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-avatar { width: 72px; height: 72px; }
    html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-avatar { font-size: 34px; }
    #screen-profile.profile-unified .has-no-cover .profile-avatar-wrap { grid-column: 1; grid-row: 1 / span 2; }
    #screen-profile.profile-unified .has-no-cover .profile-identity-copy { display: contents; }
    #screen-profile.profile-unified .has-no-cover #profile-name { grid-column: 2; grid-row: 1; align-self: end; font-size: 22px; }
    #screen-profile.profile-unified .has-no-cover .profile-rating-pill { grid-column: 2; grid-row: 2; align-self: start; justify-self: start; }
    #screen-profile.profile-unified .has-no-cover :is(.profile-identity-meta, .profile-status, .profile-form-wrap, .profile-social-row) { grid-column: 1 / -1; }
    #screen-profile.profile-unified .has-no-cover .profile-form-wrap { margin-top: 6px; }
    html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-cover-control { min-width: 36px; padding: 0; justify-content: center; }
    /* Smaller camera button on the compact avatar; the pseudo-element keeps a 44px hit area. */
    html[data-theme] body:not(.game-active) #screen-profile.profile-unified .has-no-cover .profile-avatar-control {
        width: 36px; height: 36px; min-width: 36px; min-height: 36px; right: -10px; bottom: -6px;
    }
    #screen-profile.profile-unified .has-no-cover .profile-avatar-control::after { content: ''; position: absolute; inset: -4px; }
    #screen-profile.profile-unified .has-no-cover .profile-cover-control > span {
        position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
    #screen-profile.profile-unified .profile-identity-card.has-no-cover:has(.profile-cover-control:not([hidden])) #profile-name { padding-right: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    #screen-puzzles :is(.tp-puzzle-continue, .tp-puzzle-group__head, .tp-puzzle-group__chevron, .tp-puzzle-cell),
    #screen-bot-setup .ai-setup-details > summary::after,
    #screen-profile .profile-cover-control { transition: none !important; }
}

/* ── Page headers: "More" and "League" ────────────────────────────────────────
   Both screens used the legacy .sm-page-header pill (yellow dot, faint title,
   a Font Awesome glyph that failed to render) and League stacked a second
   "season banner" under it. They now carry one calm heading each (title +
   one-line description) built only from theme tokens, so every theme works. */
html[data-theme] body:not(.game-active) #screen-more .tp-more-page {
    padding-top: clamp(24px, 3vw, 36px);
    align-content: start;
}
html[data-theme] body:not(.game-active) #screen-more .tp-more-heading {
    grid-column: 1 / -1;
    min-width: 0;
    margin: 0 0 4px;
}
html[data-theme] body:not(.game-active) #screen-more .tp-more-heading h1,
html[data-theme] body:not(.game-active) #screen-league .tp-league-head h1 {
    margin: 0;
    color: var(--tp-color-text);
    font-family: var(--tp-font-sans);
    font-size: clamp(28px, 2.6vw, 35px);
    font-weight: 720;
    line-height: 1.1;
    letter-spacing: -0.04em;
}
html[data-theme] body:not(.game-active) #screen-more .tp-more-heading p,
html[data-theme] body:not(.game-active) #screen-league .tp-league-head__copy p {
    max-width: 62ch;
    margin: 6px 0 0;
    color: var(--tp-color-text-muted);
    font-size: 14px;
    line-height: 1.45;
}

html[data-theme] body:not(.game-active) #screen-league .league-screen-inner {
    gap: 14px !important;
    padding-top: clamp(20px, 2.6vw, 30px) !important;
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px 24px;
    min-width: 0;
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head__copy { min-width: 0; flex: 1 1 280px; }
html[data-theme] body:not(.game-active) #screen-league .tp-league-head__title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head__badge {
    flex: none;
    padding: 3px 9px;
    border: 1px solid var(--tp-color-border);
    border-radius: 999px;
    background: var(--tp-color-page-secondary);
    color: var(--tp-color-text-muted);
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.06em;
    line-height: 1.3;
}
/* Compact segmented control: same row as the title on desktop, full width below on phones. */
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-switch {
    display: inline-grid;
    grid-template-columns: repeat(3, auto);
    width: auto;
    max-width: 100%;
    margin: 0;
    padding: 3px;
    gap: 2px;
    border: 1px solid var(--tp-color-border);
    border-radius: 12px;
    background: var(--tp-color-page-secondary);
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tab {
    flex-direction: row;
    gap: 6px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 9px;
    background: transparent;
    box-shadow: none;
    color: var(--tp-color-text-muted);
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-name { font-size: 14px; }
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tc { font-size: 12px; opacity: 0.8; }
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tab:hover:not(.is-active) {
    background: var(--tp-color-surface);
    color: var(--tp-color-text);
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tab.is-active {
    background: var(--tp-color-surface-raised);
    box-shadow: inset 0 -2px 0 var(--tp-color-primary);
    color: var(--tp-color-text);
}
html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tab:focus-visible {
    outline: 2px solid var(--tp-color-primary);
    outline-offset: 2px;
}
@media (max-width: 760px) {
    html[data-theme] body:not(.game-active) #screen-more .tp-more-page { padding-top: 20px; }
    html[data-theme] body:not(.game-active) #screen-league .league-screen-inner { padding-top: 20px !important; gap: 12px !important; }
    html[data-theme] body:not(.game-active) #screen-league .tp-league-head { gap: 12px; }
    html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-switch {
        display: grid;
        width: 100%;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tab {
        flex-direction: column;
        gap: 1px;
        min-height: 44px;
        padding: 4px 2px;
    }
    html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-name { font-size: clamp(12px, 3.4vw, 14px); }
    html[data-theme] body:not(.game-active) #screen-league .tp-league-head .league-pool-tc { font-size: clamp(10px, 2.8vw, 12px); }
}

/* ── Move-quality scale (game review + end-screen strip) ─────────────────────
   Seven tiers, one symbol each so the scale survives colour blindness and
   print; hues run purple, blue, green, neutral, yellow, orange, red but are
   kept earthy. Every colour is >= 4.5:1 as text on its own 14% tint over the
   dark and light surfaces. Server class → tier lives in game/move-quality.js. */
:root {
    --mq-brilliant: #C9B6F2;
    --mq-masterful: #95C0F0;
    --mq-strong: #93C98F;
    --mq-precise: #BBBEB1;
    --mq-miss: #E2C45E;
    --mq-mistake: #F2AA74;
    --mq-blunder: #F5A199;
}
html[data-theme="steppe-light"] {
    --mq-brilliant: #5E3D9E;
    --mq-masterful: #17558F;
    --mq-strong: #27602F;
    --mq-precise: #53514A;
    --mq-miss: #6B5000;
    --mq-mistake: #8A3E0B;
    --mq-blunder: #932F26;
}
.mq-chip[data-tier="brilliant"], .mq-summary__cell[data-tier="brilliant"], .match-insight__count[data-tier="brilliant"] { --mq: var(--mq-brilliant); }
.mq-chip[data-tier="masterful"], .mq-summary__cell[data-tier="masterful"], .match-insight__count[data-tier="masterful"] { --mq: var(--mq-masterful); }
.mq-chip[data-tier="strong"], .mq-summary__cell[data-tier="strong"], .match-insight__count[data-tier="strong"] { --mq: var(--mq-strong); }
.mq-chip[data-tier="precise"], .mq-summary__cell[data-tier="precise"], .match-insight__count[data-tier="precise"] { --mq: var(--mq-precise); }
.mq-chip[data-tier="miss"], .mq-summary__cell[data-tier="miss"], .match-insight__count[data-tier="miss"] { --mq: var(--mq-miss); }
.mq-chip[data-tier="mistake"], .mq-summary__cell[data-tier="mistake"], .match-insight__count[data-tier="mistake"] { --mq: var(--mq-mistake); }
.mq-chip[data-tier="blunder"], .mq-summary__cell[data-tier="blunder"], .match-insight__count[data-tier="blunder"] { --mq: var(--mq-blunder); }

.mq-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 22px;
    height: 20px;
    padding: 0 5px;
    border: 1px solid color-mix(in srgb, var(--mq) 38%, transparent);
    border-radius: var(--tp-radius-pill);
    background: color-mix(in srgb, var(--mq) 14%, var(--tp-color-surface));
    color: var(--mq);
    font-size: .74rem;
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}
.mq-chip[data-tier="precise"] { border-color: color-mix(in srgb, var(--mq) 60%, transparent); }
.mq-chip--named { height: 24px; padding: 0 10px 0 8px; }
.mq-chip__symbol { font-size: .8rem; }

.mq-tags {
    display: flex;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.mq-tag {
    min-width: 0;
    overflow: hidden;
    color: var(--tp-color-text-muted);
    font-size: .72rem;
    font-weight: 600;
    text-overflow: ellipsis;
}
#analysis-move-quality { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }

/* Review move list: ply, symbol chip, move, tags — one line per ply. */
.tp-quality-list li { grid-template-columns: 28px 24px auto minmax(0, 1fr); align-items: center; }
.tp-quality-list li .tp-quality-move { white-space: nowrap; }
.tp-quality-list li .mq-tags { justify-self: end; max-width: 100%; }
.tp-quality-list li[data-quality] { color: var(--tp-color-text); }

.mq-summary {
    display: grid;
    grid-template-columns: minmax(36px, auto) repeat(7, minmax(0, 1fr));
    gap: 4px;
    align-items: stretch;
    margin-bottom: 8px;
}
.mq-summary__side {
    align-self: center;
    max-width: 64px;
    overflow: hidden;
    color: var(--tp-color-text-muted);
    font-size: .7rem;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}
.mq-summary__cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 3px 0;
    border-radius: 8px;
    background: color-mix(in srgb, var(--mq) 14%, var(--tp-color-surface));
    line-height: 1.1;
}
.mq-summary__symbol { color: var(--mq); font-size: .85rem; font-weight: 800; }
.mq-summary__cell b { color: var(--tp-color-text); font-size: .72rem; font-variant-numeric: tabular-nums; }
.mq-summary__cell[data-zero] { background: none; opacity: .5; }

.mq-legend { margin: 0 0 8px; font-size: .76rem; }
.mq-legend > summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--tp-color-text-muted);
    cursor: pointer;
    list-style: none;
}
.mq-legend > summary::-webkit-details-marker { display: none; }
.mq-legend > summary::before {
    content: '?';
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: .68rem;
    font-weight: 700;
}
.mq-legend ul { display: grid; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.mq-legend li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 8px; align-items: start; color: var(--tp-color-text-muted); }
.mq-legend li b { color: var(--tp-color-text); }

/* End-screen strip: same symbols and colours as the review. */
.match-insight__count[data-tier] { --chip: var(--mq); }
.match-insight__count[data-tier] { min-width: 0; padding: 1px 5px; white-space: nowrap; }
.match-insight__counts { gap: 3px; }

/* ── Home: one-tap quick start chips under the primary action ───────────── */
.tp-dash-quick {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    min-width: 0;
    width: 100%;
    max-width: 380px;
    margin-top: -4px;
}
.tp-dash-quick__chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 0;
    min-height: 44px;
    padding: 4px 6px;
    border: 1px solid var(--tp-color-border-strong);
    border-radius: 9px;
    background: var(--tp-color-surface-soft);
    color: var(--tp-color-text);
    font-family: var(--tp-font-sans);
    cursor: pointer;
    transition: border-color var(--tp-game-interaction), background var(--tp-game-interaction);
}
.tp-dash-quick__time { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tp-dash-quick__kind {
    max-width: 100%;
    overflow: hidden;
    color: var(--tp-color-text-muted);
    font-size: 11px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tp-dash-quick__chip:hover { border-color: var(--tp-color-primary); background: var(--tp-color-surface-raised); }
.tp-dash-quick__chip:focus-visible { outline: 2px solid var(--tp-color-primary); outline-offset: 2px; }
@media (max-width: 767px) {
    .tp-dash-quick { max-width: none; margin-top: 0; }
}

/* ── Review move list: tags drop under the move on narrow screens ───────── */
.mq-tags:empty { display: none; }
@media (max-width: 600px) {
    .tp-quality-list li { grid-template-columns: 28px 24px minmax(0, 1fr); row-gap: 3px; }
    .tp-quality-list li .tp-quality-move { white-space: normal; overflow-wrap: anywhere; }
    .tp-quality-list li .mq-tags {
        grid-column: 3 / -1;
        justify-self: start;
        flex-wrap: wrap;
        gap: 4px 6px;
        overflow: visible;
        white-space: normal;
    }
    .tp-quality-list li .mq-tag {
        padding: 1px 7px;
        overflow: visible;
        border: 1px solid var(--tp-color-border);
        border-radius: 999px;
        font-size: .68rem;
        line-height: 1.35;
        text-overflow: clip;
        white-space: nowrap;
    }
}

/* Dark themes: regression fixes */
/* Found by a contrast/literal/border scan of the five dark presets at 375 and
   1366. Every rule is scoped away from steppe-light, which was polished
   separately and must not change. */

/* Rating toast: an old desktop rule offset it by half the 260px sidebar, so it
   sat 130px right of centre. Centre it on the viewport like the light theme. */
@media (min-width: 768px) {
    html #rating-toast.rating-toast { left: 50% !important; }
}

/* First-run tutorial: the card was a 7% white wash over a 75% scrim, so the
   page behind (cards, chips, labels) showed through the copy. Make it a solid
   raised surface; lift the copy to full opacity and give Skip a visible edge. */
html:not([data-theme="steppe-light"]) #tutorial-overlay .tutorial-bubble {
    background: var(--surface-2) !important;
    border-color: var(--border-strong) !important;
}
html:not([data-theme="steppe-light"]) #tutorial-overlay .tutorial-text {
    color: var(--text-secondary) !important;
    opacity: 1 !important;
}
html:not([data-theme="steppe-light"]) #tutorial-overlay .tutorial-skip-btn {
    color: var(--text-secondary) !important;
    border-color: var(--border-strong) !important;
}

/* AI setup start button: the play glyph kept the legacy gold (#f0c85a) on the
   pale primary fill (1.02:1) below the desktop breakpoint. Follow the label. */
html:not([data-theme="steppe-light"]) #screen-bot-setup .ai-start-button i {
    color: inherit !important;
}
html:not([data-theme="steppe-light"]) .ai-choice-card__level {
    color: color-mix(in srgb, var(--accent, var(--tp-color-primary)) 72%, #fff);
}

/* Home: small tinted labels sat at 3.3-4.0:1 on their tinted chips/cards. */
html:not([data-theme="steppe-light"]) #screen-home .tp-dash-feature__tag {
    color: color-mix(in srgb, var(--tp-color-primary) 58%, #fff);
}
html:not([data-theme="steppe-light"]) #screen-home .tp-dash-feature__date {
    color: var(--tp-color-text-muted);
}
html:not([data-theme="steppe-light"]) .tp-result-badge--loss {
    color: color-mix(in srgb, var(--tp-color-danger) 70%, #fff);
}

/* League: dark numeral on the bronze medal gradient was 4.06:1. */
html:not([data-theme="steppe-light"]) .lb-rank__medal.is-bronze { color: #0f0702; }

/* Controls whose hairline edge was at or under 1.3:1 against the surface. */
html:not([data-theme="steppe-light"]) #screen-ai-coach .coach-quick__chip,
html:not([data-theme="steppe-light"]) #screen-ai-coach .coach-followups button,
html:not([data-theme="steppe-light"]) #screen-ai-coach #ai-coach-menu {
    border-color: color-mix(in srgb, var(--text-primary) 20%, transparent);
}

/* Mobile: openings and watch
   Phones only (<= 700px); desktop and tablet keep the two-column layout.
   Openings: board -> line path -> continuations; the engine-game result filter
   sits behind one disclosure. Watch: list OR one broadcast (data-view), board
   on top with the replay controls right under it. */
.tp-openings-filter-toggle,
.tp-openings-empty__action,
.tp-openings-engine-games__empty .tp-button,
#screen-watch .tp-watch-list .tp-play-empty .tp-phase-button { display: none; }

@media (max-width: 700px) {
    html[data-theme] :is(#screen-database, #screen-watch) {
        --pit-badge: 16px;
    }

    /* Board readability: pit numbers, stone counts and kazan scores >= 12px. */
    html[data-theme] :is(#screen-database, #screen-watch) :is(.pit-number, .pit-value) {
        font-size: 12px;
        top: 2px;
    }
    html[data-theme] :is(#screen-database, #screen-watch) .pit-number { left: 2px; }
    html[data-theme] :is(#screen-database, #screen-watch) .pit-value { right: 2px; }
    html[data-theme] :is(#screen-database, #screen-watch) .kazan-score {
        font-size: 12px !important;
    }

    /* ---- Shared compact header: back, title, one action ---- */
    html[data-theme] :is(#screen-database, #screen-watch) > .tp-phase-header {
        display: grid;
        grid-template-columns: 44px minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        min-height: 60px;
        padding: 8px 10px;
        margin-bottom: 8px;
    }
    html[data-theme] :is(#screen-database, #screen-watch) > .tp-phase-header h1 {
        margin: 0;
        font-size: 20px;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }
    html[data-theme] #screen-database > .tp-phase-header p,
    html[data-theme] #screen-watch > .tp-phase-header .tp-phase-kicker {
        display: none;
    }

    /* ================= Openings ================= */
    html[data-theme] #screen-database .tp-opening-layout {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    html[data-theme] #screen-database .tp-opening-viewer {
        padding: 0;
        margin: 0 -8px;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }
    html[data-theme] #screen-database .tp-openings-path {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        margin: 8px 8px 0;
    }
    html[data-theme] #screen-database .tp-openings-path__list {
        display: flex;
        flex-wrap: nowrap;
        gap: 6px;
        margin: 0;
        padding: 0;
        list-style: none;
        overflow-x: auto;
        scrollbar-width: none;
        overscroll-behavior-x: contain;
    }
    html[data-theme] #screen-database .tp-openings-path__list::-webkit-scrollbar { display: none; }
    html[data-theme] #screen-database .tp-openings-path__item { flex: 0 0 auto; }
    html[data-theme] #screen-database .tp-openings-path__crumb {
        min-width: 44px;
        min-height: 44px;
        padding: 0 14px;
        border: 1px solid var(--border-subtle);
        border-radius: 22px;
        background: var(--surface-2);
        color: var(--text-primary);
        font-size: 14px;
        font-weight: 650;
    }
    html[data-theme] #screen-database .tp-openings-path__crumb[aria-current="true"] {
        border-color: var(--accent);
        background: var(--surface-raised);
    }
    html[data-theme] #screen-database .tp-openings-path__controls { margin: 0; }
    html[data-theme] #screen-database .tp-openings-path__controls .tp-button {
        min-height: 44px;
        padding: 0 12px;
        font-size: 14px;
    }
    html[data-theme] #screen-database .tp-openings-path__controls .tp-button:disabled { opacity: .45; }

    html[data-theme] #screen-database .tp-opening-stats {
        display: flex;
        flex-direction: column;
        gap: 8px !important;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }
    html[data-theme] #screen-database .tp-workspace-tabs,
    html[data-theme] #screen-database .tp-workspace-tabs--sub {
        margin: 0;
    }
    html[data-theme] #screen-database .tp-workspace-tabs button {
        min-height: 44px;
        font-size: 14px;
    }
    html[data-theme] #screen-database .tp-workspace-tabs button > span {
        display: block;
        font-size: 14px;
        line-height: 1.2;
        white-space: normal;
        text-overflow: clip;
        overflow-wrap: anywhere;
    }
    /* The three-screen switch (Analysis / Games / Position) is a secondary jump:
       it moves below the line, continuations and data notes. */
    html[data-theme] #screen-database .tp-workspace-tabs:not(.tp-workspace-tabs--sub) { order: 9; margin-top: 8px; }
    html[data-theme] #screen-database .tp-opening-panel {
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }
    html[data-theme] #screen-database .tp-opening-stats__heading {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        justify-content: space-between;
        gap: 2px 12px;
        margin: 0 2px 8px;
    }
    html[data-theme] #screen-database .tp-opening-stats__heading h2 {
        margin: 0;
        font-size: 18px;
    }
    html[data-theme] #screen-database .tp-opening-stats__summary {
        margin: 0;
        color: var(--text-secondary);
        font-size: 13px;
    }
    html[data-theme] #screen-database .tp-openings-moves {
        display: grid;
        gap: 8px;
    }
    html[data-theme] #screen-database .tp-opening-panel .tp-openings-move {
        min-height: 64px;
        padding: 10px 14px;
    }
    html[data-theme] #screen-database .tp-openings-move__head { gap: 10px; }
    html[data-theme] #screen-database .tp-openings-move__meta {
        gap: 4px 12px;
        font-size: 13px;
        color: var(--text-secondary);
    }
    html[data-theme] #screen-database .tp-openings-disclosure > summary,
    html[data-theme] #screen-database .tp-openings-ai__details > summary {
        min-height: 48px;
        font-size: 14px;
    }
    html[data-theme] #screen-database .tp-openings-disclosure p,
    html[data-theme] #screen-database .tp-openings-corpus * {
        font-size: max(13px, 1em);
    }

    /* Empty / error / loading: one short message, one action. */
    html[data-theme] #screen-database :is(.tp-openings-empty, .tp-openings-engine-games__empty) {
        display: grid;
        justify-items: center;
        gap: 6px;
        padding: 24px 16px;
        border: 1px dashed var(--border-subtle);
        border-radius: 14px;
        background: var(--surface-1);
        color: var(--text-secondary);
        text-align: center;
    }
    html[data-theme] #screen-database :is(.tp-openings-empty, .tp-openings-engine-games__empty) p {
        margin: 0;
        font-size: 14px;
    }
    html[data-theme] #screen-database .tp-openings-empty strong { color: var(--text-primary); font-size: 16px; }
    html[data-theme] #screen-database .tp-openings-empty__action,
    html[data-theme] #screen-database .tp-openings-engine-games__empty .tp-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        margin-top: 6px;
        padding: 0 18px;
        font-size: 14px;
    }

    /* Engine games + the single "Filters" disclosure. */
    html[data-theme] #screen-database .tp-openings-engine-games__heading { margin: 0 2px 8px; }
    html[data-theme] #screen-database .tp-openings-engine-games__heading h3 { margin: 0 0 4px; font-size: 18px; }
    html[data-theme] #screen-database .tp-openings-engine-games__note {
        margin: 0;
        color: var(--text-secondary);
        font-size: 13px;
        line-height: 1.4;
    }
    html[data-theme] #screen-database .tp-openings-filter-toggle {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        min-height: 48px;
        padding: 0 14px;
        margin-bottom: 8px;
        border: 1px solid var(--border-subtle);
        border-radius: 14px;
        background: var(--surface-2);
        color: var(--text-primary);
        font: inherit;
        font-size: 15px;
        font-weight: 650;
        text-align: left;
        cursor: pointer;
    }
    html[data-theme] #screen-database .tp-openings-filter-toggle > i {
        margin-left: auto;
        color: var(--text-secondary);
        font-size: 12px;
        transition: transform .18s ease;
    }
    html[data-theme] #screen-database .tp-openings-filter-toggle[aria-expanded="true"] > i { transform: rotate(180deg); }
    html[data-theme] #screen-database .tp-openings-filter-toggle__count {
        min-width: 22px;
        height: 22px;
        padding: 0 6px;
        border-radius: 11px;
        background: var(--accent);
        color: var(--surface-1);
        font-size: 13px;
        font-weight: 750;
        line-height: 22px;
        text-align: center;
    }
    html[data-theme] #screen-database .tp-openings-filter-toggle__count[hidden] { display: none; }
    html[data-theme] #screen-database .tp-openings-engine-games__filters {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 8px;
        overflow: visible;
    }
    html[data-theme] #screen-database #openings-panel-games:not([data-filters-open="true"]) .tp-openings-engine-games__filters {
        display: none;
    }
    html[data-theme] #screen-database .tp-openings-engine-games__filters .tp-button {
        min-height: 44px;
        justify-content: center;
        font-size: 14px;
        white-space: normal;
    }
    html[data-theme] #screen-database .tp-openings-engine-games__filters .tp-button[aria-pressed="true"] {
        border-color: var(--accent);
        background: var(--surface-raised);
        color: var(--text-primary);
        font-weight: 750;
    }
    html[data-theme] #screen-database .tp-openings-engine-games__list { display: grid; gap: 8px; }
    html[data-theme] #screen-database .tp-openings-game {
        min-height: 64px;
        padding: 10px 14px;
    }
    html[data-theme] #screen-database .tp-openings-game__meta {
        gap: 2px 10px;
        font-size: 13px;
        color: var(--text-secondary);
    }
    html[data-theme] #screen-database .tp-openings-game__head { font-size: 15px; }
    html[data-theme] #screen-database .tp-openings-game__result { font-size: 13px; }
    html[data-theme] #screen-database .tp-openings-engine-games__more { margin-top: 8px; }
    html[data-theme] #screen-database .tp-openings-engine-games__more .tp-button {
        width: 100%;
        min-height: 48px;
        justify-content: center;
        font-size: 15px;
    }

    /* ================= Watch ================= */
    html[data-theme] #screen-watch .tp-watch-layout {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    html[data-theme] #screen-watch > .tp-phase-header .tp-phase-header__actions {
        grid-column: 3;
        grid-row: 1;
        margin: 0;
    }
    html[data-theme] #screen-watch > .tp-phase-header .tp-phase-button {
        min-height: 44px;
        padding: 0 14px;
        font-size: 14px;
    }
    html[data-theme] #screen-watch > .tp-phase-header p {
        grid-column: 2 / -1;
        margin: 0;
        font-size: 13px;
        line-height: 1.35;
        color: var(--text-secondary);
    }
    html[data-theme] #screen-watch[data-view="detail"] > .tp-phase-header p,
    html[data-theme] #screen-watch[data-view="detail"] .tp-phase-header__actions { display: none; }
    html[data-theme] #screen-watch[data-view="detail"] .tp-watch-directory,
    html[data-theme] #screen-watch[data-view="list"] .tp-watch-stage { display: none; }

    /* list: full-width rows */
    html[data-theme] #screen-watch .tp-watch-directory {
        padding: 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }
    html[data-theme] #screen-watch .tp-watch-heading { margin: 0 2px 8px; }
    html[data-theme] #screen-watch .tp-watch-heading span {
        font-size: 13px;
        letter-spacing: .04em;
        color: var(--text-secondary);
    }
    html[data-theme] #screen-watch .tp-watch-heading h2 {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }
    html[data-theme] #screen-watch .tp-watch-list {
        display: grid;
        gap: 8px;
        max-height: none;
        overflow: visible;
    }
    html[data-theme] #screen-watch .tp-watch-game {
        flex: none;
        position: relative;
        display: grid;
        gap: 2px;
        min-height: 64px;
        padding: 12px 40px 12px 16px;
        border: 1px solid var(--border-subtle);
        border-radius: 14px;
        background: var(--surface-raised);
        color: var(--text-primary);
        text-align: left;
    }
    html[data-theme] #screen-watch .tp-watch-game::after {
        content: "\203A";
        position: absolute;
        top: 50%;
        right: 16px;
        transform: translateY(-50%);
        color: var(--text-secondary);
        font-size: 24px;
        line-height: 1;
    }
    html[data-theme] #screen-watch .tp-watch-game strong {
        font-size: 16px;
        font-weight: 700;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }
    html[data-theme] #screen-watch .tp-watch-game span {
        margin: 0;
        color: var(--text-secondary);
        font-size: 13px;
    }
    html[data-theme] #screen-watch .tp-watch-game.is-active { border-color: var(--accent); }
    html[data-theme] #screen-watch .tp-watch-list .tp-play-empty {
        display: grid;
        justify-items: center;
        gap: 10px;
        padding: 28px 16px;
        border: 1px dashed var(--border-subtle);
        border-radius: 14px;
        background: var(--surface-1);
        color: var(--text-secondary);
        font-size: 14px;
        text-align: center;
    }
    html[data-theme] #screen-watch .tp-watch-list .tp-play-empty p { margin: 0; }
    html[data-theme] #screen-watch .tp-watch-list .tp-play-empty .tp-phase-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        padding: 0 18px;
        font-size: 14px;
    }

    /* broadcast: board edge to edge, controls directly under it */
    html[data-theme] #screen-watch .tp-watch-stage {
        padding: 0;
        margin: 0 -8px;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
    }
    html[data-theme] #screen-watch .tp-watch-stage__heading {
        align-items: center;
        margin: 0 10px 8px;
    }
    html[data-theme] #screen-watch .tp-watch-stage__heading > div > span { display: none; }
    html[data-theme] #screen-watch .tp-watch-stage__heading h2 {
        margin: 0;
        font-size: 18px;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }
    html[data-theme] #screen-watch .tp-watch-stage__heading p {
        margin: 2px 0 0;
        color: var(--text-secondary);
        font-size: 13px;
    }
    html[data-theme] #screen-watch #watch-follow-live,
    html[data-theme] #screen-watch #watch-finished-replay {
        min-height: 48px;
        font-size: 15px;
    }
    html[data-theme] #screen-watch #watch-finished-replay { display: flex; width: calc(100% - 20px); margin: 10px 10px 0; justify-content: center; }
    html[data-theme] #screen-watch #watch-finished-replay[hidden] { display: none; }
    html[data-theme] #screen-watch #watch-live-status {
        margin: 8px 10px 0;
        padding: 14px 16px;
        border: 1px dashed var(--border-subtle);
        border-radius: 14px;
        background: var(--surface-1);
        color: var(--text-secondary);
        font-size: 14px;
        text-align: center;
    }
    html[data-theme] #screen-watch #watch-live-status[hidden] { display: none; }
}

/* Safety net: a dialog overlay that is displayed without `.open` is transparent
 * (glass-system.css). It must not also swallow clicks, or the page looks frozen. */
html[data-theme] :is(.modal-overlay, .overlay)[role="dialog"]:not(.open) { pointer-events: none; }

/* The compact facts row sets its own display, which would otherwise defeat `hidden`. */
html[data-theme] #end-screen .match-result-card [hidden],
html[data-theme] #end-screen .match-result-card .match-result-details[hidden] { display: none !important; }

/* Owner-view audit fixes (2026-10-08). */
/* Profile: legacy title ornament renders as a broken glyph; the header band adds nothing. */
#screen-profile .profile-context-header .sub-screen-title::after { content: none !important; }
html[data-theme="steppe-light"] #screen-profile.profile-unified .profile-context-header {
    background: transparent !important;
    border-color: transparent !important;
}
/* Statistics: an empty rating history should not reserve the chart's height. */
#screen-stats #stats-rating-chart:has(> .tp-data-state--empty) { min-height: 0; height: auto; }
#screen-stats #stats-rating-chart > .tp-data-state--empty { min-height: 0; height: auto; padding-block: 28px; }
/* AI coach, desktop: the empty state belongs in the middle of the free area, not at its bottom edge. */
@media (min-width: 1025px) {
    #screen-ai-coach:has(#ai-coach-empty:not([hidden])) .coach-chat-scroll {
        place-items: center;
        align-content: center;
        padding-block-end: 0;
    }
}

/* Puzzles are not timed: no clocks next to the players. */
body.puzzle-game #screen-game .match-clock { display: none !important; }

/* League pools are categories, not single time controls: no "3+1" next to the name. */
#screen-league .league-pool-tc { display: none !important; }

/* ── Game review: what the player came for is on the first screen ──────────
 * Accuracy and the tier summary lead the side panel, the evaluation graph sits
 * under the board it drives, the move list scrolls inside the panel. The board
 * itself is untouched apart from its width. */
html[data-theme] body:not(.game-active) #screen-analysis #analysis-page-title {
    font-size: 24px;
    line-height: 1.15;
    letter-spacing: -.02em;
}
html[data-theme] body:not(.game-active) #screen-analysis #analysis-source-detail { margin-top: 2px; font-size: 14px; }

html[data-theme] #screen-analysis .tp-analysis-board-graph {
    margin-top: 10px;
    padding: 6px 10px;
    border: 1px solid var(--tp-color-border, var(--border-subtle));
    border-radius: 12px;
    background: var(--tp-color-surface, var(--surface-1));
}
html[data-theme] #screen-analysis .tp-analysis-board-graph .tp-review-graph {
    display: block;
    width: 100%;
    height: 44px;
    margin: 0;
    cursor: pointer;
    touch-action: none;
}

/* Review panel, top to bottom: the move under the cursor, the score sheet, the
 * stepper. Game-level numbers live behind the "Report" tab. */
html[data-theme] body:not(.game-active) #screen-analysis .tp-move-panel { gap: 8px; padding: 0; }
html[data-theme] #screen-analysis .tp-move-panel [hidden] { display: none !important; }

html[data-theme] #screen-analysis .rv-coach {
    display: grid;
    align-content: start;
    gap: 6px;
    min-height: 104px;
    padding: 10px 12px;
    border: 1px solid var(--tp-color-border, var(--border-subtle));
    border-radius: 12px;
    background: var(--tp-color-surface, var(--surface-1));
}
html[data-theme] #screen-analysis .rv-coach__head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
html[data-theme] #screen-analysis .rv-coach__head > strong {
    font-size: 16px;
    line-height: 1.25;
    font-variant-numeric: tabular-nums;
    color: var(--tp-color-text, var(--text-primary));
}
html[data-theme] #screen-analysis .rv-coach__tier { display: inline-flex; align-items: center; gap: 6px; order: 2; }
html[data-theme] #screen-analysis .rv-coach__tier:empty { display: none; }
html[data-theme] #screen-analysis .rv-coach__eval {
    order: 3;
    margin-left: auto;
    font-size: 13px;
    color: var(--tp-color-text-muted, var(--text-secondary));
}
html[data-theme] #screen-analysis .rv-coach__why {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
    color: var(--tp-color-text-muted, var(--text-secondary));
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
html[data-theme] #screen-analysis .rv-coach__better {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 14px;
    color: var(--tp-color-text-muted, var(--text-secondary));
}
html[data-theme] #screen-analysis .rv-coach__why { order: 2; }
html[data-theme] #screen-analysis .tp-review-phases__head { background: none !important; }
html[data-theme] #screen-analysis .tp-review-phases__head > b {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--tp-color-text-muted, var(--text-secondary));
}
html[data-theme] #screen-analysis .rv-coach__better > b { color: var(--tp-color-text, var(--text-primary)); font-weight: 650; }
html[data-theme] #screen-analysis .rv-coach__retry {
    margin-left: auto;
    min-height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-contrast, #fff);
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
}

html[data-theme] #screen-analysis .rv-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    padding: 2px;
    border-radius: 10px;
    background: var(--tp-color-muted-surface, var(--surface-2));
}
html[data-theme] #screen-analysis .rv-tabs > button {
    min-height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--tp-color-text-muted, var(--text-secondary));
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
html[data-theme] #screen-analysis .rv-tabs > button.is-active {
    background: var(--tp-color-surface, var(--surface-1));
    color: var(--tp-color-text, var(--text-primary));
    box-shadow: 0 1px 2px rgb(0 0 0 / .12);
}

html[data-theme] #screen-analysis .tp-move-panel__moves,
html[data-theme] #screen-analysis .tp-move-panel__summary {
    min-height: 120px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--tp-color-border, var(--border-subtle));
    border-radius: 12px;
    background: var(--tp-color-surface, var(--surface-1));
}
html[data-theme] #screen-analysis .rv-moves { margin: 0; padding: 4px; list-style: none; }
html[data-theme] #screen-analysis .rv-moves > li {
    display: grid;
    grid-template-columns: 34px 1fr 1fr;
    align-items: center;
    gap: 2px;
}
html[data-theme] #screen-analysis .rv-moves > li:nth-child(even) { background: color-mix(in srgb, var(--tp-color-text, var(--text-primary)) 3%, transparent); border-radius: 6px; }
html[data-theme] #screen-analysis .rv-moves > li > b {
    font-size: 12px;
    font-weight: 500;
    text-align: right;
    padding-right: 8px;
    font-variant-numeric: tabular-nums;
    color: var(--tp-color-text-muted, var(--text-secondary));
}
html[data-theme] #screen-analysis .rv-moves button {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 28px;
    padding: 0 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--tp-color-text, var(--text-primary));
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: left;
    cursor: pointer;
}
html[data-theme] #screen-analysis .rv-moves button:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
html[data-theme] #screen-analysis .rv-moves button.is-current {
    background: color-mix(in srgb, var(--accent) 18%, var(--tp-color-surface, var(--surface-1)));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}
html[data-theme] #screen-analysis .rv-moves button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
html[data-theme] #screen-analysis .rv-moves .mq-chip { flex: none; transform: scale(.86); }

html[data-theme] #screen-analysis .tp-move-panel__summary { display: grid; align-content: start; gap: 10px; padding: 10px; }
html[data-theme] #screen-analysis .tp-move-panel__summary .tp-review-accuracy {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0;
}
html[data-theme] #screen-analysis .tp-move-panel__summary .tp-review-accuracy > div {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--tp-color-muted-surface, var(--surface-2));
}
html[data-theme] #screen-analysis .tp-move-panel__summary .tp-review-accuracy span {
    font-size: 13px;
    color: var(--tp-color-text-muted, var(--text-secondary));
}
html[data-theme] #screen-analysis .tp-move-panel__summary .tp-review-accuracy strong {
    font-size: 20px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--tp-color-text, var(--text-primary));
}
html[data-theme] #screen-analysis .tp-move-panel__summary .mq-summary,
html[data-theme] #screen-analysis .tp-move-panel__summary .tp-review-phases { margin: 0; }

html[data-theme] body:not(.game-active) #screen-analysis .tp-move-panel__nav { gap: 6px; }
html[data-theme] body:not(.game-active) #screen-analysis .tp-move-panel__nav > strong {
    min-width: 9ch;
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--tp-color-text-muted, var(--text-secondary));
}
html[data-theme] body:not(.game-active) #screen-analysis .tp-move-panel__step {
    flex: 1 1 0;
    width: auto;
    height: 38px;
    border-radius: 10px;
}

@media (min-width: 1100px) {
    /* One screen, no scrolling: a one-line page header, then the board sized
     * from the viewport height with the working panel beside it. Measured on a
     * 1920x1080 laptop at 150% scaling, which leaves about 1280x580. */
    html[data-theme] body:not(.game-active) #screen-analysis { padding-top: 12px !important; --an-board-h: calc(100vh - 167px); }
    html[data-theme] body:not(.game-active) #screen-analysis[data-analysis-state="completed"] { --an-board-h: calc(100vh - 235px); }
    html[data-theme] body:not(.game-active) #screen-analysis > .tp-phase-header {
        min-height: 40px !important;
        padding-block: 0 !important;
        margin-bottom: 8px !important;
        align-items: center;
    }
    html[data-theme] body:not(.game-active) #screen-analysis > .tp-phase-header > div {
        display: flex;
        align-items: baseline;
        flex-wrap: wrap;
        gap: 2px 12px;
        /* room for the position status that sits at the right end of this line */
        padding-right: 340px;
    }
    html[data-theme] body:not(.game-active) #screen-analysis #analysis-page-title { margin: 0 !important; font-size: 22px !important; line-height: 1.2 !important; }
    html[data-theme] body:not(.game-active) #screen-analysis #analysis-source-detail { margin: 0 !important; font-size: 14px !important; }
    html[data-theme] body:not(.game-active) #screen-analysis > .tp-phase-header .tp-phase-icon-button { width: 36px; height: 36px; }

    html[data-theme] body:not(.game-active) #screen-analysis .tp-analysis-layout {
        position: relative;
        grid-template-columns: minmax(0, calc(var(--an-board-h) * 1.785)) minmax(320px, 420px);
        justify-content: center;
        align-items: start;
        gap: 18px;
    }
    html[data-theme] body:not(.game-active) #screen-analysis .tp-analysis-viewer-card { width: 100%; max-width: none; }
    html[data-theme] body:not(.game-active) #screen-analysis #analysis-material-board { max-height: none; }
    /* "Position" repeats the page title; its status moves up into the header line. */
    html[data-theme] body:not(.game-active) #screen-analysis .tp-analysis-board-bar {
        position: absolute;
        top: -48px;
        right: 0;
        height: 40px;
        display: flex;
        align-items: center;
        margin: 0;
        padding: 0;
    }
    html[data-theme] body:not(.game-active) #screen-analysis .tp-analysis-board-bar > h2 { display: none; }
    html[data-theme] body:not(.game-active) #screen-analysis .tp-analysis-board-bar > strong { font-size: 13px; font-weight: 600; color: var(--tp-color-text-muted, var(--text-secondary)); }
    html[data-theme] body:not(.game-active) #screen-analysis #analysis-setup { width: auto; padding: 14px; }

    html[data-theme] body:not(.game-active) #screen-analysis[data-analysis-state="completed"] .tp-move-panel {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 167px);
        min-height: 300px;
    }
    html[data-theme] body:not(.game-active) #screen-analysis[data-analysis-state="completed"] .tp-move-panel > * { flex: none; }
    html[data-theme] body:not(.game-active) #screen-analysis[data-analysis-state="completed"] .tp-move-panel > :is(.tp-move-panel__moves, .tp-move-panel__summary) { flex: 1 1 0; min-height: 0; }
}
@media (min-width: 1100px) and (max-height: 680px) {
    /* Short screens: the move card gives its spare lines to the score sheet. */
    html[data-theme] #screen-analysis .rv-coach { min-height: 0; padding-block: 8px; gap: 4px; }
    html[data-theme] #screen-analysis .rv-coach__why { -webkit-line-clamp: 2; font-size: 13px; }
    html[data-theme] body:not(.game-active) #screen-analysis .tp-move-panel__step { height: 32px; }
    html[data-theme] #screen-analysis .rv-moves button { min-height: 24px; }
    html[data-theme] #screen-analysis .tp-analysis-board-graph { margin-top: 8px; padding: 4px 8px; }
    html[data-theme] #screen-analysis .tp-analysis-board-graph .tp-review-graph { height: 36px; }
    /* Narrow pits: the otau number and its count must not overlap. */
    html[data-theme] #screen-analysis #analysis-material-board .pit :is(.pit-number, .pit-value) {
        width: 20px !important;
        height: 20px !important;
        min-width: 0 !important;
        font-size: 11px !important;
    }
    html[data-theme] #screen-analysis #analysis-material-board .pit .pit-number { left: 3px !important; right: auto !important; }
    html[data-theme] #screen-analysis #analysis-material-board .pit .pit-value { right: 3px !important; left: auto !important; }
}
@media (min-width: 1100px) {
    /* A finished review has no use for the "record is valid" status. */
    html[data-theme] body:not(.game-active) #screen-analysis[data-analysis-state="completed"] .tp-analysis-board-bar { display: none; }
}
@media (max-width: 1099px) {
    /* The stepper stays next to the board; the sheet scrolls in its own box. */
    html[data-theme] #screen-analysis .tp-move-panel__nav { order: -1; }
    html[data-theme] #screen-analysis .tp-move-panel__moves,
    html[data-theme] #screen-analysis .tp-move-panel__summary { max-height: 46vh; }
}
/* With a review on screen the "Position / record is valid" bar says nothing new. */
html[data-theme] #screen-analysis[data-analysis-state="completed"] .tp-analysis-board-bar { display: none; }

/* ── Game database, desktop: one screen, same frame as the analysis page ──
 * One-line header, board sized from the viewport height, and a side panel of
 * the same height whose continuation list scrolls inside it. */
@media (min-width: 1100px) {
    html[data-theme] body:not(.game-active) #screen-database { padding-top: 12px !important; padding-bottom: 0 !important; --db-board-h: calc(100vh - 219px); }
    html[data-theme] body:not(.game-active) #screen-database > .tp-phase-header {
        min-height: 40px !important;
        padding-block: 0 !important;
        margin-bottom: 8px !important;
        align-items: center;
    }
    html[data-theme] body:not(.game-active) #screen-database > .tp-phase-header > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 12px; }
    html[data-theme] body:not(.game-active) #screen-database #opening-explorer-title { margin: 0 !important; font-size: 22px !important; line-height: 1.2 !important; }
    html[data-theme] body:not(.game-active) #screen-database #opening-explorer-detail { margin: 0 !important; font-size: 14px !important; }
    html[data-theme] body:not(.game-active) #screen-database > .tp-phase-header .tp-phase-icon-button { width: 36px; height: 36px; }

    html[data-theme] body:not(.game-active) #screen-database .tp-opening-layout {
        grid-template-columns: minmax(0, calc(var(--db-board-h) * 1.785)) minmax(320px, 420px) !important;
        justify-content: center;
        align-items: start;
        gap: 18px;
    }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-viewer {
        padding: 0 !important;
        border: 0 !important;
        background: none !important;
        box-shadow: none !important;
    }
    html[data-theme] body:not(.game-active) #screen-database #opening-material-board { max-height: none; }
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-path { margin-top: 8px !important; min-height: 44px; }

    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats {
        display: flex !important;
        flex-direction: column;
        gap: 8px;
        height: calc(100vh - 167px);
        min-height: 300px;
        padding: 10px !important;
        overflow: hidden;
    }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats > * { flex: none; margin: 0 !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats .tp-workspace-tabs { min-height: 0 !important; padding: 2px !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats .tp-workspace-tabs > button { min-height: 32px !important; height: 32px !important; padding-block: 0 !important; font-size: 13px !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats > .tp-opening-panel:not([hidden]) {
        flex: 1 1 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 0 !important;
        border: 0 !important;
        background: none !important;
    }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-panel > * { flex: none; margin: 0 !important; }
    /* The tab already says "Continuations"; only the count line stays. */
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats__heading > h2,
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-engine-games__heading > h3 { display: none; }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-stats__summary { margin: 0 !important; padding-inline: 4px; font-size: 13px !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-panel > :is(#openings-moves, #openings-engine-games) {
        flex: 1 1 0;
        min-height: 0;
        max-height: none !important;
        height: auto !important;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-panel > :is(#openings-moves, #openings-engine-games) {
        grid-auto-rows: max-content;
        align-content: start;
    }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-panel > :is(#openings-moves, #openings-engine-games) > * { flex: 0 0 auto; }
    html[data-theme] body:not(.game-active) #screen-database .tp-opening-panel .tp-openings-move {
        min-height: 44px !important;
        padding: 6px 8px !important;
        gap: 4px !important;
    }
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-move__pit,
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-move__share { font-size: 14px !important; line-height: 1.2 !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-move__bar { height: 3px !important; margin: 0 !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-move__meta { margin: 0 !important; font-size: 12px !important; line-height: 1.2 !important; }
    html[data-theme] body:not(.game-active) #screen-database .tp-openings-disclosure > summary { min-height: 28px !important; padding-block: 2px !important; font-size: 13px !important; }
}
@media (min-width: 1100px) and (max-height: 680px) {
    /* Narrow pits: the otau number and its count must not overlap. */
    html[data-theme] #screen-database #opening-material-board .pit :is(.pit-number, .pit-value) {
        width: 20px !important;
        height: 20px !important;
        min-width: 0 !important;
        font-size: 11px !important;
    }
    html[data-theme] #screen-database #opening-material-board .pit .pit-number { left: 3px !important; right: auto !important; }
    html[data-theme] #screen-database #opening-material-board .pit .pit-value { right: 3px !important; left: auto !important; }
}

/* The otau number is a plain corner digit on the analysis and openings boards, as on
   the review boards (review-marks.css) and the game board. Two 20px plaques side by
   side do not fit a 36px phone pit and lay one number over the other; the stone
   count keeps its plaque. Placed after the size-specific blocks above so it wins at
   every width. */
html[data-theme] :is(#screen-analysis #analysis-material-board, #screen-database #opening-material-board) .pit .pit-number {
    top: 4px !important;
    left: 4px !important;
    right: auto !important;
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: none !important;
    box-shadow: none !important;
    color: rgba(74, 49, 24, 0.62) !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    line-height: 1 !important;
}

/* Kazakh: Unbounded has no ә ғ қ ң ө ұ ү һ, so those letters fell back to
 * another typeface in the middle of a heading. In Kazakh the display role goes
 * to one typeface that carries the whole alphabet. */
html[lang="kk"],
html[lang="kk"] body {
    --font-display: 'Segoe UI', Roboto, 'SF Pro Display', 'Helvetica Neue', 'Noto Sans', system-ui, sans-serif;
    --tp-font-display: 'Segoe UI', Roboto, 'SF Pro Display', 'Helvetica Neue', 'Noto Sans', system-ui, sans-serif;
}

/* ── Accessibility settings that were saved but changed nothing ─────────────
 * Text size: the old rule set a font-size on the page container, while every
 * text style below it is in px, so nothing moved. The content area is scaled
 * as a whole instead. */
body[data-text-size="small"] .tp-product-page > .tp-product-content { zoom: .92; }
body[data-text-size="large"] .tp-product-page > .tp-product-content { zoom: 1.12; }

/* Higher contrast: stronger text, secondary text and borders, per palette. The
 * old rule forced white text, which only suited dark themes and was overridden
 * by the theme tokens anyway. */
html[data-theme="steppe-light"] body[data-high-contrast="true"],
html[data-theme="steppe-light"] body[data-high-contrast="true"] .screen {
    --text-primary: #000000;
    --text-secondary: #2B2A24;
    --border-subtle: #6F6959;
    --tp-color-text: #000000;
    --tp-color-text-muted: #2B2A24;
    --tp-color-border: #6F6959;
    --tp-product-text: #000000;
    --tp-product-muted: #2B2A24;
    --tp-product-border: #6F6959;
}
html[data-theme]:not([data-theme="steppe-light"]) body[data-high-contrast="true"],
html[data-theme]:not([data-theme="steppe-light"]) body[data-high-contrast="true"] .screen {
    --text-primary: #FFFFFF;
    --text-secondary: #E4E1D8;
    --border-subtle: rgba(255, 255, 255, .55);
    --tp-color-text: #FFFFFF;
    --tp-color-text-muted: #E4E1D8;
    --tp-color-border: rgba(255, 255, 255, .55);
    --tp-product-text: #FFFFFF;
    --tp-product-muted: #E4E1D8;
    --tp-product-border: rgba(255, 255, 255, .55);
}
body[data-high-contrast="true"] .screen :is(small, p, span, label, dd, dt, li) { opacity: 1; }
body[data-high-contrast="true"] :is(button, a, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid var(--accent) !important;
    outline-offset: 2px !important;
}

/* Large touch targets: every control outside the board is at least 48px. */
body[data-large-touch-targets="true"] .screen:not(#screen-game) :is(button, select, [role="tab"], a[class*="button"], input:not([type="checkbox"]):not([type="radio"]):not([type="range"])):not(.pit) {
    min-height: 48px;
    min-width: 48px;
}
/* Controls that were already taller keep their height. */
body[data-large-touch-targets="true"] .screen:not(#screen-game) :is(.tp-section-nav, .tp-settings-nav) button { min-height: 58px !important; }
body[data-large-touch-targets="true"] .tp-settings-row { min-height: 68px; }

/* Local sparring opponent switch (only rendered when this machine serves it). */
#screen-bot-setup .ai-local-opponent {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px dashed var(--tp-color-border, var(--border-subtle));
    border-radius: 12px;
    cursor: pointer;
}
#screen-bot-setup .ai-local-opponent input { width: 18px; height: 18px; accent-color: var(--accent); }
#screen-bot-setup .ai-local-opponent span { display: grid; gap: 2px; }
#screen-bot-setup .ai-local-opponent strong { font-size: 14px; color: var(--tp-color-text, var(--text-primary)); }
#screen-bot-setup .ai-local-opponent small { font-size: 12px; color: var(--tp-color-text-muted, var(--text-secondary)); }

/* ══════════════════════════════════════════════════════════════════════════
   Theme picker (2026-10-10)

   Three round swatches in one row, the theme name underneath. This block is
   the single owner of the picker's look; the older rules in rewards-themes,
   settings-glass, desktop-settings, learning-settings and steppe-light drew a
   bordered card per theme and are overridden here, not edited.

   Scope: only `.tp-theme-picker` and what is inside it, plus the vertical
   alignment of its own row. Nothing else on Settings is touched.

   Contract with JS (ui/modals.js `setTheme`, main.js `initThemeControls`):
   `[data-theme-choice]`, `.is-selected`, `aria-checked`, role radio/radiogroup.

   Each swatch is drawn from three colours of the theme it stands for, never
   from the active theme, so the picker reads the same wherever it is shown:
     --tp-swatch-lit / --tp-swatch-deep   surface, lit from the upper left
     --tp-swatch-accent(-lit)             the accent segment
     --tp-swatch-edge                     hairline that keeps the disc defined
   Archived themes keep ready-made values in _archive/themes-archived.css.

   `!important` appears only where an older `!important` forces it:
   steppe-light.css paints `.tp-theme-choice` backgrounds, and
   product-ui-cleanup.css sets every `strong` inside a settings row.
   ══════════════════════════════════════════════════════════════════════════ */
html[data-theme] body #screen-settings .tp-theme-picker {
    --tp-swatch-size: 44px;
    --tp-swatch-ring: 2px;
    --tp-swatch-ring-gap: 3px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
    gap: 0;
    width: 100%;
    min-width: 0;
}

html[data-theme] body #screen-settings .tp-theme-choice {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    align-content: start;
    gap: 8px;
    padding: 8px 2px 6px;
    border: 0;
    border-radius: 14px;
    background: transparent !important;
    box-shadow: none;
    color: var(--tp-color-text-muted, var(--text-secondary));
    text-align: center;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: color 160ms ease;
}

html[data-theme] body #screen-settings .tp-theme-choice.is-selected {
    box-shadow: none;
    color: var(--tp-color-text, var(--text-primary));
}

/* Keyboard focus is the app-wide `:focus-visible` ring (visual-polish.css and
   the theme overrides), drawn around the whole choice. It is deliberately not
   restyled here: a rounded rectangle for focus and a circle for selection
   cannot be mistaken for one another. */

/* The disc. */
html[data-theme] body #screen-settings .tp-theme-choice__preview {
    position: relative;
    width: var(--tp-swatch-size);
    height: var(--tp-swatch-size);
    display: block;
    border: 0;
    border-radius: 50%;
    background:
        linear-gradient(135deg, transparent 0 62.6%, var(--tp-swatch-accent-lit) 63.8%, var(--tp-swatch-accent) 100%),
        linear-gradient(135deg, var(--tp-swatch-lit) 6%, var(--tp-swatch-deep) 60%);
    box-shadow:
        inset 0 0 0 1px var(--tp-swatch-edge),
        0 1px 2px rgba(0, 0, 0, 0.22);
    transition: transform 180ms cubic-bezier(0.2, 0, 0, 1);
}

html[data-theme] body #screen-settings .tp-theme-choice__preview--night {
    --tp-swatch-lit: #34302d;
    --tp-swatch-deep: #12100e;
    --tp-swatch-accent: #d2a75e;
    --tp-swatch-accent-lit: #e6c07c;
    --tp-swatch-edge: rgba(236, 231, 223, 0.16);
}

html[data-theme] body #screen-settings .tp-theme-choice__preview--charcoal {
    --tp-swatch-lit: #3a2815;
    --tp-swatch-deep: #100b07;
    --tp-swatch-accent: #d4a24c;
    --tp-swatch-accent-lit: #e8bc6c;
    --tp-swatch-edge: rgba(245, 226, 192, 0.16);
}

html[data-theme] body #screen-settings .tp-theme-choice__preview--light {
    --tp-swatch-lit: #fffcf4;
    --tp-swatch-deep: #e5dfd2;
    --tp-swatch-accent: #176c68;
    --tp-swatch-accent-lit: #2a8a85;
    --tp-swatch-edge: rgba(39, 41, 34, 0.2);
}

/* Selection: a ring in the active accent, separated from the disc by a gap.
   It is a pseudo-element rather than an outline or a spread shadow so the gap
   stays transparent over glass and never needs to know the row colour. */
html[data-theme] body #screen-settings .tp-theme-choice__preview::after {
    content: '';
    position: absolute;
    inset: calc(-1 * (var(--tp-swatch-ring) + var(--tp-swatch-ring-gap)));
    border: var(--tp-swatch-ring) solid var(--tp-color-primary, var(--accent));
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: opacity 160ms ease, transform 220ms cubic-bezier(0.2, 0, 0, 1), border-color 160ms ease;
}

html[data-theme] body #screen-settings .tp-theme-choice.is-selected .tp-theme-choice__preview::after {
    opacity: 1;
    transform: none;
}

/* Feedback starts on press, not on release. */
html[data-theme] body #screen-settings .tp-theme-choice:active .tp-theme-choice__preview {
    transform: scale(0.94);
    transition-duration: 90ms;
}

@media (hover: hover) {
    html[data-theme] body #screen-settings .tp-theme-choice:hover {
        color: var(--tp-color-text, var(--text-primary));
    }
    html[data-theme] body #screen-settings .tp-theme-choice:not(.is-selected):hover .tp-theme-choice__preview::after {
        border-color: color-mix(in srgb, var(--tp-color-text, var(--text-primary)) 34%, transparent);
        opacity: 1;
        transform: none;
    }
}

/* The name: small, one line, centred under the disc. */
html[data-theme] body #screen-settings .tp-theme-choice > .tp-theme-choice__name {
    display: block;
    min-width: 0;
    max-width: 100%;
}

html[data-theme] body #screen-settings .tp-theme-choice strong {
    display: block;
    margin: 0;
    color: inherit !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    line-height: 1.25;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

/* Phones wide enough for it get a slightly larger disc. */
@media (min-width: 360px) and (max-width: 900px) {
    html[data-theme] body #screen-settings .tp-theme-picker { --tp-swatch-size: 48px; }
}

/* From 901px the row is horizontal: copy on the left, the picker hugging the
   right edge at its natural width. */
@media (min-width: 901px) {
    html[data-theme] body #screen-settings .tp-settings-row--theme { align-items: center; }
    html[data-theme] body #screen-settings .tp-theme-picker {
        flex: 0 0 auto;
        width: auto;
        grid-template-columns: repeat(3, 92px);
        /* Optical alignment: the last name, not the empty side of its column,
           lines up with the toggles and selects in the rows below. */
        margin-inline-end: -6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html[data-theme] body #screen-settings .tp-theme-choice,
    html[data-theme] body #screen-settings .tp-theme-choice__preview { transition: none; }
    html[data-theme] body #screen-settings .tp-theme-choice__preview::after {
        transform: none;
        transition: opacity 120ms linear;
    }
    html[data-theme] body #screen-settings .tp-theme-choice:active .tp-theme-choice__preview { transform: none; }
}

/* The in-app "reduce motion" setting mirrors the media query. */
html[data-theme] body[data-reduced-motion="true"] #screen-settings .tp-theme-choice__preview,
html[data-theme] body[data-reduced-motion="true"] #screen-settings .tp-theme-choice:active .tp-theme-choice__preview,
html[data-theme] body[data-reduced-motion="true"] #screen-settings .tp-theme-choice__preview::after {
    transform: none;
    transition: none;
}

@media (prefers-contrast: more) {
    html[data-theme] body #screen-settings .tp-theme-picker { --tp-swatch-ring: 3px; }
    html[data-theme] body #screen-settings .tp-theme-choice { color: var(--tp-color-text, var(--text-primary)); }
}
