/* ==========================================================================
   Chessty mobile composition

   Esta hoja se carga despues de los estilos de cada pagina. No replica la
   interfaz de escritorio: define una navegacion, densidad y orden tactiles
   comunes sin ocultar desbordamientos con overflow-x en el documento.
   ========================================================================== */

.mobile-dock { display: none; }
.friend-chat-back { display: none; }
.analysis-mobile-label { display: none; }
.mobile-table-scroll { display: contents; }
.mobile-drawer { display: none; }
.home-mobile-auth { display: none; }
.tactical-progress-expand { display: none; }

@media (max-width: 900px) {
    :root {
        --mobile-gutter: clamp(.6rem, 2.8vw, .9rem);
        --mobile-dock-space: calc(88px + env(safe-area-inset-bottom));
        --mobile-card-radius: 15px;
    }

    html,
    body,
    .shell,
    main {
        min-width: 0;
        width: 100%;
        max-width: 100%;
    }

    body {
        display: block;
        min-height: 100dvh;
        padding-bottom: 0;
    }

    .shell { padding-bottom: var(--mobile-dock-space); }

    .sidebar { display: none; }

    main,
    body:has(.home-club) main,
    body:has(.play-room) main,
    main:has(.workspace-page),
    main:has(.content-page),
    main:has(.analysis-lab),
    .auth-page main {
        padding: max(var(--mobile-gutter), env(safe-area-inset-top)) max(var(--mobile-gutter), env(safe-area-inset-right)) 1.5rem max(var(--mobile-gutter), env(safe-area-inset-left));
    }

    .site-legal-footer {
        margin-top: .5rem;
        padding: 1rem .65rem;
        flex-wrap: wrap;
    }

    .mobile-dock {
        position: fixed;
        z-index: 900;
        right: max(.45rem, env(safe-area-inset-right));
        bottom: max(.45rem, env(safe-area-inset-bottom));
        left: max(.45rem, env(safe-area-inset-left));
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        height: 68px;
        padding: .3rem;
        border: 1px solid color-mix(in srgb, var(--theme-border) 84%, transparent);
        border-radius: 18px;
        background: color-mix(in srgb, var(--theme-surface) 96%, transparent);
        box-shadow: 0 12px 30px rgba(8, 20, 30, .24);
    }

    .mobile-dock__item {
        position: relative;
        min-width: 0;
        min-height: 58px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: .14rem;
        padding: .3rem .08rem;
        border: 0;
        border-radius: 13px;
        color: var(--theme-muted);
        background: transparent;
        font: inherit;
        text-align: center;
        text-decoration: none;
        cursor: pointer;
    }

    .mobile-dock__item img,
    .mobile-dock__item svg {
        width: 23px;
        height: 23px;
        flex: 0 0 auto;
        object-fit: contain;
    }

    .mobile-dock__item svg { fill: currentColor; }

    .mobile-dock__item span {
        display: block;
        max-width: 100%;
        overflow: hidden;
        font-size: .6875rem;
        font-weight: 800;
        letter-spacing: -.015em;
        line-height: 1.2;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-dock__item.is-active {
        color: var(--theme-accent-text);
        background: color-mix(in srgb, var(--theme-accent) 13%, transparent);
    }

    .mobile-dock__item.is-active::before {
        position: absolute;
        top: 2px;
        width: 22px;
        height: 3px;
        border-radius: 999px;
        background: var(--theme-accent);
        content: "";
    }

    .mobile-dock__more { position: static; min-width: 0; }
    .mobile-dock__more > summary { width: 100%; list-style: none; }
    .mobile-dock__more > summary::-webkit-details-marker { display: none; }

    .mobile-dock__menu {
        position: fixed;
        right: max(.6rem, env(safe-area-inset-right));
        bottom: calc(82px + env(safe-area-inset-bottom));
        display: grid;
        width: min(18rem, calc(100vw - 1.2rem));
        max-height: calc(100dvh - 110px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow-y: auto;
        overscroll-behavior: contain;
        gap: .2rem;
        padding: .45rem;
        border: 1px solid var(--theme-border);
        border-radius: 17px;
        background: var(--theme-surface);
        box-shadow: 0 18px 48px rgba(8, 20, 30, .3);
        transform-origin: right bottom;
    }

    .mobile-dock__more:not([open]) .mobile-dock__menu { display: none; }

    .mobile-dock__menu a {
        min-height: 48px;
        display: grid;
        grid-template-columns: 28px minmax(0, 1fr);
        align-items: center;
        gap: .65rem;
        padding: .55rem .7rem;
        border-radius: 11px;
        color: var(--theme-text);
        text-decoration: none;
    }

    .mobile-dock__menu a:active {
        background: var(--theme-input);
        transform: scale(.985);
    }

    .mobile-dock__menu img,
    .mobile-dock__menu a > span {
        width: 24px;
        height: 24px;
        display: grid;
        place-items: center;
        object-fit: contain;
        color: var(--theme-accent-text);
        font-size: 1.05rem;
    }

    .mobile-dock__menu strong { min-width: 0; font-size: 1rem; }
    .mobile-energy64 {
        display: flex;
        align-items: center;
        gap: .4rem;
        min-height: 42px;
        padding: .5rem .6rem;
        border-radius: .6rem;
        color: var(--text);
        background: color-mix(in srgb, var(--theme-accent) 9%, transparent);
    }
    .mobile-energy64 b { font-size: 1rem; }
    .mobile-energy64 strong { color: var(--theme-accent); }
    .energy64-profile-card { grid-template-columns: 2.8rem minmax(0, 1fr); gap: .75rem; padding: 1rem; }
    .energy64-profile-card__flame { width: 2.8rem; height: 2.8rem; border-radius: .85rem; font-size: 1.45rem; }
    .energy64-profile-card__stats { grid-column: 1 / -1; grid-template-columns: repeat(2, 1fr); padding: .65rem 0 0; border-top: 1px solid color-mix(in srgb, #e89f34 28%, transparent); border-left: 0; }
    .chessty-level { grid-template-columns: 2.8rem minmax(0, 1fr); gap: .7rem; padding: .78rem; }
    .chessty-level__crown { width: 2.8rem; height: 2.8rem; font-size: 1.45rem; }
    .chessty-level__heading { align-items: start; flex-direction: column; gap: .3rem; }
    .chessty-level__heading p { font-size: .72rem; }
    .chessty-level__foot { font-size: .61rem; }
    .players-directory-header { align-items: flex-start; flex-direction: column; }
    .players-directory-header .btn { width: 100%; }
    .players-directory-search { align-items: stretch; flex-direction: column; }
    .players-directory-search .btn { width: 100%; }
    .mobile-dock__craft { background: color-mix(in srgb, var(--theme-accent) 10%, transparent); }

    /* Superficies mas ligeras: en telefono la jerarquia depende del orden,
       no de sombras tridimensionales grandes. */
    .card,
    .play-board-stage,
    .play-control-deck,
    .bot-roster,
    .bot-brief,
    .admin-control-panel,
    .admin-launch-card,
    .tournament-card {
        border-radius: var(--mobile-card-radius);
        box-shadow: 0 3px 12px color-mix(in srgb, var(--theme-shadow) 72%, transparent);
    }

    .page-header,
    .puzzle-page-header,
    .play-room-intro,
    .analysis-lab__intro,
    .bot-lobby-intro,
    .admin-heading {
        min-width: 0;
        margin-bottom: .55rem;
    }

    .workspace-kicker,
    .play-room-kicker,
    .bot-lobby-kicker,
    .home-club-kicker {
        font-size: .75rem;
        letter-spacing: .13em;
    }

    /* Los cuatro modos funcionan como una barra contextual de 48px. */
    .puzzle-nav-mobile {
        min-height: 48px;
        gap: .2rem;
        margin-bottom: .45rem;
        padding: .2rem;
        border-radius: 14px;
    }

    .puzzle-nav-mobile .puzzle-mode-link {
        min-height: 44px;
        padding: .28rem .12rem;
        border-radius: 10px;
    }

    .puzzle-nav-mobile .puzzle-mode-link svg { width: 17px; height: 17px; }
    .puzzle-nav-mobile .puzzle-mode-link::after {
        content: attr(data-mobile-label); position: static; height: auto;
        background: none; font-size: .75rem; line-height: 1.25;
    }

    /* Tableros: se usa todo el ancho util y las coordenadas conservan un
       margen pequeño. Nunca se recorta .cg-wrap. */
    .play-board-stage,
    .puzzle-workspace .board-col,
    .analysis-board-stage,
    .custom-training-board {
        width: 100%;
        max-width: none;
        min-width: 0;
        justify-self: stretch;
    }

    .play-board-stage,
    .puzzle-board-stage,
    .analysis-board-stage {
        padding: .28rem;
        border-radius: 13px;
    }

    .play-room .board-frame,
    .puzzle-workspace .puzzle-board-frame > .board-frame,
    .analysis-board-frame,
    .custom-training-board .board-frame {
        width: 100%;
        max-width: 100%;
        padding: 2px 2px 18px 18px;
    }

    .puzzle-workspace .puzzle-board-frame {
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    .play-room coords,
    .puzzle-workspace coords,
    .analysis-lab coords,
    .custom-trainer-room coords { font-size: 9px; }

    .play-room coords.ranks,
    .puzzle-workspace coords.ranks,
    .analysis-lab coords.ranks,
    .custom-trainer-room coords.ranks { left: -15px; }

    .play-room coords.files,
    .puzzle-workspace coords.files,
    .analysis-lab coords.files,
    .custom-trainer-room coords.files { bottom: -15px; }

    .cg-wrap { overflow: visible; }
    .cg-wrap cg-board { overflow: hidden; }

    .analysis-board-row {
        grid-template-columns: 18px minmax(0, 1fr);
        gap: .18rem;
    }

    .analysis-eval {
        width: 18px;
        min-width: 18px;
        border-radius: 8px;
    }

    .analysis-console { max-height: none; }

    /* Las paginas de gestion y comunidad presentan filas, no miniaturas de
       tablas de escritorio. */
    .admin-tabs {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .25rem;
    }

    .admin-tabs a { min-width: 0; padding-inline: .35rem; text-align: center; }

    .admin-launchpad,
    .admin-metrics,
    .community-page .dash,
    .community-page .dash-main,
    .community-page .dash-side {
        gap: .65rem;
    }

    .admin-launch-card-primary {
        grid-row: auto;
        min-height: 94px;
    }

    .admin-launch-card { padding: .8rem; }

    dialog,
    .admin-confirm-dialog,
    .play-promotion-dialog,
    .play-confirm-dialog {
        max-width: calc(100vw - 1rem);
        max-height: calc(100dvh - 1rem);
    }
}

@media (max-width: 560px) {
    .home-stage-copy { padding: 1rem .85rem .9rem; }

    .home-stage h1 {
        max-width: 12ch;
        font-size: clamp(2.15rem, 11.5vw, 3rem);
    }

    .home-club-lead { font-size: .86rem; }

    .home-puzzle-feature .board-frame { padding: 2px 2px 18px 18px; }

    .puzzle-page-header h1,
    .analysis-lab__intro h1,
    .play-room-intro h1,
    .bot-lobby-intro h1 { font-size: 1.55rem; }

    .puzzle-board-foot { min-height: 42px; padding: .5rem .4rem .2rem; }
    .puzzle-action-card { padding: .9rem; }
    .puzzle-action-card .card-title { font-size: 1.35rem; line-height: 1.05; }
    .puzzle-result-panel { padding: .75rem; }

    .bot-lobby-shell .bot-item {
        min-height: 88px;
        grid-template-columns: 52px minmax(0, 1fr);
    }

    .bot-lobby-shell .bot-avatar { width: 52px; height: 68px; }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
    :root { --mobile-dock-space: calc(70px + env(safe-area-inset-bottom)); }

    .mobile-dock {
        right: .35rem;
        bottom: max(.3rem, env(safe-area-inset-bottom));
        left: auto;
        width: 20rem;
        height: 56px;
        border-radius: 15px;
    }

    .mobile-dock__item { min-height: 46px; }
    .mobile-dock__item img,
    .mobile-dock__item svg { width: 19px; height: 19px; }
    .mobile-dock__item span { font-size: .6875rem; }
    .mobile-dock__menu { bottom: calc(65px + env(safe-area-inset-bottom)); }
}

/* Shared touch layout: desktop styles above 900px remain unchanged. */
@media (max-width: 900px) {
    html { scroll-padding-bottom: var(--mobile-dock-space); }
    body { font-size: 1rem; line-height: 1.5; }
    .page, .card, .dash, .dash-main, .dash-side, .game-layout,
    .account-row > div, .profile-header > div { min-width: 0; }
    .page-title { font-size: clamp(1.65rem, 7.5vw, 2.2rem); line-height: 1.15; overflow-wrap: anywhere; }
    .home-stage h1, .home-stage h1 span { white-space: normal; overflow-wrap: anywhere; }
    .card { padding: 1rem; }
    .card-title { font-size: 1.1rem; line-height: 1.3; }
    .card-note, .field-hint, .field-label, .empty, .muted,
    .friends-empty, .friends-header > div > p, .player-directory-person p,
    .player-directory-person small, .friend-card__main > span:last-child > span:last-child {
        font-size: .875rem; line-height: 1.5;
    }
    .workspace-kicker, .players-directory-kicker, .friends-section__heading p { font-size: .75rem; }
    .btn, .btn-sm, button:not(.puzzle-route-node), .tab, .admin-tabs a {
        min-height: 44px; touch-action: manipulation;
    }
    .btn, .btn-sm { font-size: .9375rem; line-height: 1.3; white-space: normal; }
    input:not([type=checkbox]):not([type=radio]):not([type=range]), select, textarea {
        min-width: 0; max-width: 100%; min-height: 44px; font-size: 16px;
    }
    input[type=checkbox], input[type=radio] { accent-color: var(--theme-accent); }
    button, a, summary { -webkit-tap-highlight-color: transparent; }
    :is(a, button, input, select, textarea, summary):focus-visible {
        outline: 2px solid var(--theme-accent); outline-offset: 3px;
    }
    .btn:active, .mobile-dock__item:active { filter: brightness(.93); }
    .pagination { flex-wrap: wrap; gap: .5rem; }
    .pagination a { min-height: 44px; display: inline-flex; align-items: center; padding-inline: .75rem; }
    .mobile-table-scroll, .table-responsive, .table-wrap {
        display: block; max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain;
    }
    .mobile-table-scroll table { font-size: .875rem; }
    .mobile-table-scroll th, .mobile-table-scroll td { padding: .75rem .6rem; }
    .mobile-table-scroll:focus-visible { outline: 2px solid var(--theme-accent); }
    dialog, .analysis-dialog, .modal-content {
        max-width: calc(100vw - 1.25rem); max-height: calc(var(--mobile-viewport-height, 100dvh) - 24px);
        overflow-y: auto; overscroll-behavior: contain;
    }
    .analysis-dialog { padding: 1rem; }
    .analysis-dialog footer, .modal-actions { flex-wrap: wrap; gap: .5rem; }

    /* Lobby: show the format choice before a large decorative scoreboard. */
    .battle-page:not(.battle-active-page) .battle-arena {
        padding: 1.1rem; gap: 1rem; border-radius: 16px;
    }
    .battle-page:not(.battle-active-page) .battle-copy h1 { font-size: 2rem; }
    .battle-page:not(.battle-active-page) .battle-scoreboard { gap: .75rem; }
    .battle-page:not(.battle-active-page) .battle-player-card {
        min-height: 0; padding: .6rem; gap: .3rem; border-radius: 12px;
        grid-template-columns: 32px minmax(0, 1fr); display: grid; align-items: center;
    }
    .battle-page:not(.battle-active-page) .battle-avatar { width: 32px; height: 32px; grid-row: span 2; }
    .battle-page:not(.battle-active-page) .battle-score { font-size: 1.3rem; line-height: 1; }
    .battle-page:not(.battle-active-page) .battle-lives { grid-column: 1 / -1; justify-content: center; }
    .battle-lobby-grid .battle-development-card { min-height: 0; gap: .75rem; padding: 1rem; }
    .battle-lobby-grid .battle-development-card .btn { margin-top: 0; }
    .battle-time-picker { margin-block: .75rem; padding: 0; }
    .battle-time-picker__presets { gap: .5rem; }
    .battle-time-picker__presets button { font-size: .9375rem; padding: .5rem .2rem; }
    .battle-time-picker__custom { font-size: 1rem; }
    .battle-time-picker__note { font-size: .875rem; line-height: 1.5; margin-block: .75rem; }
    .puzzle-rule-grid strong, .puzzle-rule-grid h3 { font-size: .9375rem; }
    .puzzle-rule-grid p { font-size: .8125rem; line-height: 1.45; }
    .battle-clock, .battle-match-clock, .play-clock, .player-clock, .rush-clock {
        font-variant-numeric: tabular-nums; font-size: clamp(1.35rem, 6vw, 1.75rem);
    }
    .rush-play-layout > .rush-console-head, .battle-match-layout > .battle-round-summary {
        position: sticky; top: env(safe-area-inset-top); z-index: 30; width: 100%;
        margin-bottom: .5rem; border: 1px solid var(--theme-border); border-radius: 12px;
        background: var(--theme-surface); overflow: hidden;
    }
    .rush-play-layout > .rush-console-head > div { padding: .5rem .875rem; }
    .rush-play-layout > .rush-console-head .rush-timer { font-size: 1.75rem; }
    .battle-match-layout > .battle-round-summary { padding: .5rem .875rem; }
    .battle-active-page .battle-clock strong { font-size: 1.75rem; }
    .play-player-bar, .battle-participant { min-height: 48px; }
    .play-player-name, .battle-participant strong { overflow-wrap: anywhere; }

    /* Keep the board primary; supporting panels don't need desktop-height voids. */
    .analysis-console { min-height: 0; height: auto; }
    .analysis-tree-section { min-height: 0; flex: initial; }
    .analysis-tree { min-height: 80px; max-height: 240px; }
    .analysis-nav { gap: .25rem; }
    .analysis-nav button, .analysis-icon-btn { min-width: 44px; }
    .analysis-text-btn, .analysis-empty, .analysis-player__turn,
    .analysis-engine__local-meta, .analysis-engine__status { font-size: .8125rem; }
    .analysis-player { min-height: 38px; padding-block: .3rem; }
    .analysis-lab__workspace { gap: .75rem; }
    .puzzle-route-card .puzzle-map-viewport { max-height: 65dvh; overflow-y: auto; overscroll-behavior-y: contain; }
    .puzzle-board-foot, .puzzle-status { font-size: .875rem; }
    .puzzle-action-card .card-title { line-height: 1.25; }
    .custom-filter-grid, .settings-grid { min-width: 0; }
    .custom-training-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
    .bot-game-room .move-list, .bot-game-room .move-table { min-height: 100px; max-height: 220px; }

    .friend-inbox-row__actions { margin-left: 0; }
    .friend-card, .player-directory-row { padding: .875rem .75rem; gap: .75rem; }
    .friend-card__main strong, .player-directory-person h2 { font-size: 1rem; }
    .friend-card__label { font-size: .6875rem; }
    .friends-section__heading h2 { font-size: 1rem; }
    .friend-card__actions .btn, .player-directory-row__action .btn { min-width: 64px; font-size: .875rem; }
    .game-history--boards .game-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .game-history--boards .game-row-main {
        grid-template-columns: 76px minmax(0, 1fr); gap: .75rem;
        width: 100%; min-height: 120px; padding: .75rem;
    }
    .game-history--boards .game-mini-board { width: 76px; height: 76px; align-self: center; }
    .game-history--boards .game-row-main::after { content: none; }
    .game-history--boards .game-row-summary__top { flex-wrap: wrap; gap: .35rem .6rem; }
    .game-history--boards .game-result-label { font-size: .9375rem; white-space: nowrap; }
    .game-history--boards .game-rival-line { display: block; }
    .game-history--boards .game-rival-line > span { display: none; }
    .game-history--boards .game-rival-line strong { font-size: .9375rem; white-space: normal; overflow-wrap: anywhere; }
    .game-history--boards .game-row-summary__meta { display: grid; gap: .2rem; font-size: .75rem; }
    .game-history--boards .game-row-summary__meta > * { padding: 0; border: 0; }
    .game-history--boards .game-row-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; padding: 0 .75rem .75rem; }
    .game-history--boards .game-action-link { min-width: 0; min-height: 44px; font-size: .8125rem; }
    .game-row .game-opponent { font-size: 1rem; }
    .game-row .game-meta, .game-row .game-date { font-size: .8125rem; line-height: 1.45; }
    .profile-header h1, .profile-info h2 { overflow-wrap: anywhere; }
    .admin-launchpad, .admin-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-launch-card-primary { grid-column: 1 / -1; }
    .admin-tabs a { font-size: .875rem; }

    /* Chat is a viewport, not a page as tall as its entire history. */
    body:has(.friend-chat-page) { padding: 0; }
    body:has(.friend-chat-page) .shell { padding: 0; }
    body:has(.friend-chat-page) .site-legal-footer { display: none; }
    .friend-chat-page {
        position: fixed; z-index: 800; top: var(--mobile-viewport-top, 0px); left: 0; right: 0;
        width: 100%; max-width: none; height: calc(var(--mobile-viewport-height, 100dvh) - var(--mobile-dock-space));
        margin: 0; padding: max(.25rem, env(safe-area-inset-top)) env(safe-area-inset-right) 0 env(safe-area-inset-left);
    }
    .friend-chat-page .direct-message-layout { display: block; height: 100%; min-height: 0; border: 0; border-radius: 0; }
    .friend-chat-page .direct-message-list, .friend-chat-page .direct-message-profile { display: none; }
    .friend-chat-page .friend-chat-room { height: 100%; min-height: 0; border: 0; border-radius: 0; }
    .friend-chat-page .friend-chat-messages { min-height: 0; flex: 1 1 0; padding: .75rem; overscroll-behavior: contain; }
    .friend-chat-header, .friend-chat-room__notice, .friend-chat-compose, .friend-chat-status { flex-shrink: 0; }
    .friend-chat-header { padding: .6rem .5rem; }
    .friend-chat-back { display: grid; place-items: center; flex: 0 0 44px; min-height: 44px; color: var(--text); text-decoration: none; font-size: 1.5rem; border-radius: 10px; }
    .friend-chat-header__identity { flex: 1; }
    .friend-chat-header h1 { font-size: 1rem; }
    .friend-chat-header p { font-size: .625rem; letter-spacing: .05em; }
    .friend-chat-room__notice { font-size: .75rem; padding: .4rem .75rem; overflow-wrap: anywhere; }
    .friend-message { max-width: 88%; box-shadow: none; }
    .friend-message p { font-size: 1rem; line-height: 1.45; overflow-wrap: anywhere; }
    .friend-message time { font-size: .6875rem; }
    .friend-chat-compose { position: static; padding: .5rem .75rem; }
    .friend-chat-compose textarea { font-size: 16px; min-height: 46px; max-height: min(128px, 25dvh); }
    .friend-chat-compose .btn { min-width: 46px; min-height: 46px; font-size: 1rem; }
    .friend-chat-status { font-size: .75rem; padding-bottom: max(.4rem, env(safe-area-inset-bottom)); }
    body:has(.friend-chat-compose:focus-within) .mobile-dock, .mobile-keyboard-open .mobile-dock { display: none; }
    body:has(.friend-chat-compose:focus-within) .friend-chat-page { height: var(--mobile-viewport-height, 100dvh); }
}

/* Analysis: task controls immediately follow the board, not the move tree. */
@media (max-width: 900px) {
    .analysis-lab .analysis-lab__intro { margin-bottom: .25rem; }
    .analysis-lab .analysis-player { min-height: 30px; padding-block: .2rem; }
    .analysis-lab .analysis-player--bottom { margin-bottom: 0; }
    .analysis-lab__workspace { row-gap: .5rem; }
    .analysis-mobile-toolbar {
        position: sticky; top: env(safe-area-inset-top, 0px); z-index: 40;
        display: grid; grid-template-columns: minmax(0, 1fr) auto;
        gap: 0 .5rem; padding: .35rem .5rem 0; min-width: 0;
        border: 1px solid var(--theme-border); border-radius: 14px;
        background: var(--theme-surface); box-shadow: 0 4px 12px var(--theme-shadow);
    }
    .analysis-mobile-toolbar .analysis-nav {
        order: 0; grid-column: 1 / -1; padding: 0 0 .35rem; gap: .3rem;
        display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    }
    .analysis-mobile-toolbar .analysis-nav button { width: 100%; min-width: 0; height: 44px; }
    .analysis-mobile-toolbar .analysis-nav__divider { display: none; }
    .analysis-mobile-toolbar .analysis-engine__topline { order: 1; margin: 0; min-width: 0; }
    .analysis-mobile-toolbar .analysis-engine-switch { min-height: 48px; gap: .4rem; font-size: .875rem; }
    .analysis-mobile-toolbar .analysis-engine__status { display: none; }
    .analysis-mobile-toolbar .analysis-console__head {
        order: 2; min-width: 0; padding: .3rem 0; border: 0; background: none;
    }
    .analysis-mobile-toolbar .analysis-console__head > div:first-child { display: none; }
    .analysis-mobile-toolbar .analysis-console__actions { gap: .35rem; }
    .analysis-mobile-toolbar .analysis-icon-btn {
        display: flex; justify-content: center; width: auto; min-width: 0;
        gap: .3rem; padding: .4rem .5rem; font-size: .8125rem;
    }
    .analysis-mobile-toolbar .analysis-icon-btn[hidden] { display: none; }
    .analysis-mobile-toolbar .analysis-icon-btn svg { width: 17px; height: 17px; }
    .analysis-mobile-label { display: inline; }
    .analysis-mobile-more { order: 3; grid-column: 1 / -1; border-top: 1px solid var(--theme-border); }
    .analysis-mobile-more > summary {
        display: flex; justify-content: space-between; align-items: center;
        min-height: 44px; color: var(--theme-muted); cursor: pointer; font-size: .8125rem; list-style: none;
    }
    .analysis-mobile-more > summary::-webkit-details-marker { display: none; }
    .analysis-mobile-more > summary::after { content: '+'; font-size: 1.15rem; }
    .analysis-mobile-more[open] > summary::after { content: '−'; }
    .analysis-mobile-more .analysis-console__foot { padding: 0 0 .6rem; border: 0; }
    .analysis-mobile-more .analysis-console__foot button { font-size: .75rem; }
    .analysis-lab .analysis-console { min-height: 0; max-height: none; }
    .analysis-lab .analysis-engine { order: 0; padding: .75rem; }
    .analysis-lab .analysis-engine__local-meta { margin: 0 0 .5rem; }
    .analysis-lab .analysis-engine__summary { margin: .4rem 0; }
    .analysis-lab .analysis-lines { max-height: 150px; overflow-y: auto; }
    .analysis-lab .analysis-tree-section { order: 1; padding: .75rem; border-top: 1px solid var(--theme-border); }
    .analysis-lab:not(:has([data-engine-toggle]:checked)) .analysis-engine__local-meta,
    .analysis-lab:not(:has([data-engine-toggle]:checked)) .analysis-engine__summary,
    .analysis-lab:not(:has([data-engine-toggle]:checked)) .analysis-lines { display: none; }
    .analysis-lab:not(:has([data-engine-toggle]:checked)) .analysis-engine { padding: 0; }
}

/* Focused mobile analysis workspace: engine above, board central, tools below. */
@media (max-width: 900px) {
    body:has(.analysis-mobile-heading) .mobile-dock,
    body:has(.analysis-mobile-heading) .site-legal-footer { display: none; }
    body:has(.analysis-mobile-heading) .shell { padding-inline: 0; }
    .analysis-lab:has(.analysis-mobile-heading) { padding: 0 0 calc(96px + env(safe-area-inset-bottom)); }
    .analysis-lab:has(.analysis-mobile-heading) > .analysis-lab__intro { display: none; }
    .analysis-mobile-heading { display: flex; align-items: center; gap: 12px; padding: 4px 8px; min-height: 56px; }
    .analysis-mobile-heading > a { display: grid; place-items: center; width: 44px; height: 44px; font-size: 36px; text-decoration: none; color: var(--theme-text); }
    .analysis-mobile-heading > strong { flex: 1; font-size: 22px; color: var(--theme-title); }
    .analysis-mobile-heading .analysis-console__head { padding: 0; border: 0; background: none; }
    .analysis-mobile-heading .analysis-console__head > div:first-child,
    .analysis-mobile-heading .analysis-mobile-label { display: none; }
    .analysis-mobile-heading .analysis-icon-btn { width: 44px; height: 44px; }
    .analysis-mobile-heading [hidden] { display: none; }
    .analysis-mobile-overview { padding: 0 12px; min-width: 0; }
    .analysis-mobile-overview .analysis-eval { position: relative; width: 100%; height: 22px; min-height: 0; border-radius: 3px; margin-bottom: 6px; }
    .analysis-mobile-overview .analysis-eval { padding: 0; }
    .analysis-mobile-overview .analysis-eval__track { position: absolute; inset: 0; min-height: 0; border-radius: 3px; }
    .analysis-mobile-overview .analysis-eval__track::after { height: 100%; width: var(--eval, 50%); }
    .analysis-mobile-overview .analysis-eval__score { z-index: 1; position: absolute; top: 0; left: 6px; bottom: auto; font-size: 14px; line-height: 22px; min-height: 0; color: #1d2429; text-shadow: 0 0 2px white; }
    .analysis-mobile-overview .analysis-engine { padding: 0; border: 0; background: none; }
    .analysis-mobile-overview .analysis-engine__local-meta { display: none; }
    .analysis-mobile-overview .analysis-engine__summary { display: flex; margin: 4px 0; font-size: 12px; }
    .analysis-mobile-overview .analysis-lines { max-height: 84px; gap: 3px; }
    .analysis-mobile-overview .analysis-line { padding: 3px 0; background: none; border: 0; grid-template-columns: 44px minmax(0, 1fr); }
    .analysis-mobile-overview .analysis-line__depth { display: none; }
    .analysis-mobile-overview .analysis-line__moves { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; }
    .analysis-mobile-overview .analysis-line__score { border-radius: 4px; background: var(--theme-surface); padding: 4px; font-size: 14px; }
    .analysis-lab .analysis-board-row { display: block; }
    .analysis-lab .analysis-board-stage { width: 100%; max-width: min(100%, 600px); justify-self: center; }
    .analysis-lab .analysis-board-wrap { padding: 0 8px 18px 20px; }
    .analysis-lab .analysis-board-wrap .board-frame { padding: 0; width: 100%; max-width: none; }
    .analysis-lab .analysis-player { display: none; }
    .analysis-mobile-toolbar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 850; border-radius: 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); display: flex; gap: 8px; background: var(--theme-surface); }
    .analysis-mobile-toolbar .analysis-nav { flex: 1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); padding: 0; border: 0; }
    .analysis-mobile-toolbar .analysis-nav button { display: flex; flex-direction: column; justify-content: center; gap: 5px; height: 60px; border: 0; background: none; }
    .analysis-mobile-toolbar .analysis-nav button[data-nav="first"],
    .analysis-mobile-toolbar .analysis-nav button[data-nav="last"],
    .analysis-mobile-toolbar .analysis-nav button[data-delete-branch] { display: none; }
    .analysis-mobile-toolbar .analysis-nav button[data-flip-board] { order: -1; }
    .analysis-mobile-toolbar .analysis-mobile-label { font-size: 12px; }
    .analysis-mobile-more { order: -1; flex: 0 0 24%; border: 0; }
    .analysis-mobile-more > summary { height: 60px; justify-content: center; font-weight: 700; color: var(--theme-title); }
    .analysis-mobile-more > summary::after { display: none; }
    .analysis-mobile-more[open] { position: static; }
    .analysis-mobile-more[open] > .analysis-engine__topline,
    .analysis-mobile-more[open] > .analysis-console__foot { position: absolute; left: 12px; right: 12px; background: var(--theme-surface); padding: 16px; border: 1px solid var(--theme-border); }
    .analysis-mobile-more[open] > .analysis-engine__topline { bottom: calc(100% + 144px); border-radius: 16px 16px 0 0; }
    .analysis-mobile-more[open] > .analysis-mobile-extra { position: absolute; bottom: calc(100% + 72px); left: 12px; right: 12px; height: 72px; display: flex; gap: 8px; padding: 8px 16px; background: var(--theme-surface); border-inline: 1px solid var(--theme-border); }
    .analysis-mobile-extra button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; color: var(--theme-title); background: var(--theme-surface); border: 1px solid var(--theme-border); border-radius: 8px; }
    .analysis-mobile-extra svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
    .analysis-mobile-extra [hidden] { display: none; }
    .analysis-mobile-more[open] > .analysis-console__foot { bottom: 100%; min-height: 72px; border-radius: 0 0 16px 16px; }
    .analysis-lab .analysis-console { margin: 0 12px; }
    .analysis-lab .analysis-tree { min-height: 48px; max-height: 180px; }
    .analysis-lab .analysis-tree-section { min-height: 0; }
}

/* Mobile paint budget. Keep game-state highlights, piece movement, loading
   spinners and focus rings; remove only costly decorative compositing. */
@media (max-width: 900px) {
    .notification-rail {
        top: max(4.35rem, calc(.45rem + env(safe-area-inset-top)));
        right: max(.45rem, env(safe-area-inset-right));
        width: min(20.5rem, calc(100vw - 4.5rem));
        gap: .45rem;
    }
    .notification-rail > div { gap: .45rem; }
    .king-check-alert,
    .friend-online-toast { box-shadow: 0 4px 12px rgba(3, 14, 24, .2); }
    .king-check-alert { grid-template-columns: 2.15rem minmax(0, 1fr); padding: .7rem; gap: .3rem .6rem; animation-name: king-check-arrive; }
    .king-check-alert__piece { width: 2.15rem; height: 2.15rem; border-radius: .62rem; font-size: 1.2rem; }
    .king-check-alert__copy span { font-size: .78rem; }
    .friend-online-toast { min-height: 3.7rem; padding: .65rem .75rem; }
    .friends-presence-widget { top: max(.45rem, env(safe-area-inset-top)); right: max(.12rem, env(safe-area-inset-right)); width: auto; }
    .friends-presence-toggle { min-height: 2.65rem; padding-right: .5rem; }
    .friends-presence-toggle__label { display: none; }
    .friends-presence-panel { width: min(20rem, calc(100vw - 1.5rem)); }

    .bot-lobby-glow, .hero-board-glow { display: none; }

    .bot-lobby-intro-note, .bot-roster, .bot-brief {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
        background: var(--theme-surface);
    }
    .admin-confirm-dialog::backdrop,
    .play-promotion-dialog::backdrop,
    .analysis-dialog::backdrop,
    .analysis-promotion::backdrop {
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    /* A filtered shadow per piece multiplies the cost across every mini-board. */
    .cg-wrap piece, .cg-wrap piece.dragging,
    .home-feature-board, .logo-full { filter: none; }

    .bot-roster, .bot-brief, .analysis-console,
    .play-board-stage, .puzzle-board-stage, .analysis-board-stage,
    .board-frame, .cg-wrap cg-board {
        box-shadow: none;
    }
    .mobile-dock, .mobile-dock__menu, .analysis-mobile-toolbar {
        background: var(--theme-surface);
        box-shadow: 0 2px 6px rgba(8, 20, 30, .16);
    }

    /* Online status stays visible without continuously repainting its shadow. */
    .status-dot { animation: none; box-shadow: none; }
    .analysis-engine__status:is([data-state="thinking"], [data-state="downloading"]) i,
    .play-room .player-clock.is-low,
    .play-search-ring { animation: none; }
    .energy64-streak-celebration__fire { filter: none; animation-iteration-count: 3; }
    .btn, .mobile-dock__item, .mobile-dock__menu a {
        transition-property: background-color, color, opacity;
        transition-duration: 120ms;
    }
    .btn:active, .mobile-dock__item:active { filter: none; }
}

/* Drawer navigation replaces the phone dock with the complete desktop map. */
@media (max-width: 900px) {
    .shell { padding-bottom: 1.25rem; }
    .mobile-dock { display: none; }
    .mobile-drawer { display: block; position: fixed; z-index: 1100; inset: 0; pointer-events: none; }
    .mobile-drawer__trigger, .mobile-drawer__close { display: grid; width: 48px; height: 48px; place-items: center; border: 0; border-radius: 12px; color: var(--theme-title); background: var(--theme-surface); cursor: pointer; }
    .mobile-drawer__trigger { position: fixed; z-index: 2; top: max(.45rem, env(safe-area-inset-top)); left: max(.45rem, env(safe-area-inset-left)); list-style: none; pointer-events: auto; box-shadow: 0 2px 8px var(--theme-shadow); }
    .mobile-drawer__trigger::-webkit-details-marker, .mobile-drawer__group > summary::-webkit-details-marker { display: none; }
    .mobile-drawer__trigger svg, .mobile-drawer__close svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
    .mobile-drawer[open] { pointer-events: auto; }
    .mobile-drawer[open] .mobile-drawer__trigger { opacity: 0; pointer-events: none; }
    .mobile-drawer__scrim { position: absolute; inset: 0; background: rgba(5, 12, 18, .58); opacity: 0; transition: opacity 180ms var(--ease-out); }
    .mobile-drawer[open] .mobile-drawer__scrim { opacity: 1; }
    .mobile-drawer__panel { position: absolute; top: 0; bottom: 0; left: 0; display: flex; width: min(82vw, 338px); min-width: 280px; flex-direction: column; overflow: hidden; color: var(--theme-text); background: var(--theme-sidebar); box-shadow: 16px 0 36px rgba(5, 12, 18, .28); transform: translateX(-104%); transition: transform 200ms var(--ease-out); }
    .mobile-drawer[open] .mobile-drawer__panel { transform: translateX(0); }
    .mobile-drawer__head { min-height: calc(64px + env(safe-area-inset-top)); display: flex; align-items: end; justify-content: space-between; padding: env(safe-area-inset-top) 12px 8px 20px; border-bottom: 1px solid var(--theme-border); }
    .mobile-drawer__brand { display: flex; align-items: center; height: 44px; }
    .mobile-drawer__brand img { width: 144px; height: auto; max-height: 40px; object-fit: contain; object-position: left center; }
    .mobile-drawer__close { background: transparent; box-shadow: none; }
    .mobile-drawer__links { display: grid; overflow-y: auto; overscroll-behavior: contain; padding: 12px 10px; gap: 3px; }
    .mobile-drawer__links > a, .mobile-drawer__group > summary { min-height: 52px; display: grid; grid-template-columns: 31px minmax(0, 1fr) 20px; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 11px; color: var(--theme-text); font-size: 1rem; text-decoration: none; list-style: none; }
    .mobile-drawer__links > a { grid-template-columns: 31px minmax(0, 1fr); }
    .mobile-drawer__links > a:active, .mobile-drawer__group > summary:active { background: color-mix(in srgb, var(--theme-accent) 14%, transparent); }
    .mobile-drawer__links > a.is-active, .mobile-drawer__group[open] > summary { color: var(--theme-accent-text); background: color-mix(in srgb, var(--theme-accent) 12%, transparent); }
    .mobile-drawer__links img, .mobile-drawer__home, .mobile-drawer__craft { width: 28px; height: 28px; object-fit: contain; font-size: 1.55rem; line-height: 28px; text-align: center; }
    .mobile-drawer__craft { color: var(--theme-accent); }
    .mobile-drawer__group > summary { cursor: pointer; }
    .mobile-drawer__group > summary > span:last-child { font-size: 1.25rem; text-align: right; transition: transform 180ms var(--ease-out); }
    .mobile-drawer__group[open] > summary > span:last-child { transform: rotate(180deg); }
    .mobile-drawer__group > a { min-height: 42px; display: flex; align-items: center; margin-left: 41px; padding: 5px 10px; border-radius: 9px; color: var(--theme-muted); font-size: .9rem; font-weight: 700; text-decoration: none; }
    .mobile-drawer__group > a:active { color: var(--theme-title); background: var(--theme-input); }
    .mobile-drawer__group b { min-width: 20px; height: 20px; display: inline-grid; place-items: center; margin-left: auto; border-radius: 999px; color: #fff; background: var(--theme-error); font-size: .7rem; }
    .mobile-drawer__foot { display: grid; gap: 6px; margin-top: auto; padding: 12px 14px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--theme-border); }
    .mobile-drawer__account { min-height: 52px; display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; color: var(--theme-text); text-decoration: none; }
    .mobile-drawer__account img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
    .mobile-drawer__account span { display: grid; gap: 1px; }
    .mobile-drawer__account small { color: var(--theme-muted); font-size: .72rem; }
    .mobile-drawer__setting { min-height: 44px; display: flex; align-items: center; gap: 11px; padding: 6px; color: var(--theme-muted); font-size: .9rem; font-weight: 700; text-decoration: none; }
    .mobile-drawer__setting span { width: 28px; text-align: center; font-size: 1.2rem; }
    body:has(.mobile-drawer[open]) { overflow: hidden; }
    main:not(:has(.analysis-lab)) { padding-top: max(4rem, calc(2.2rem + env(safe-area-inset-top))); }
    /* El cajón reemplaza el regreso a Inicio del analizador y evita dos
       acciones superpuestas en la esquina superior izquierda. */
    .analysis-mobile-heading > a { display: none; }
    .analysis-mobile-heading > strong { margin-left: 56px; }
    .home-club-guest .home-mobile-auth {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: .75rem;
        margin: 1.1rem 0 .2rem;
    }
    .home-mobile-auth .btn { min-height: 52px; justify-content: center; }
    .home-mobile-auth__signup { min-height: 44px; display: grid; place-items: center; padding: 0 .35rem; color: var(--theme-accent-text); font-size: .9rem; font-weight: 800; text-decoration: none; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    .mobile-dock__item,
    .mobile-dock__menu a { transition: none; }
    .king-check-alert,
    .friend-online-toast { animation: none; }
}

/* Analysis on phones: one viewport, with the real controls in the console.
   No detached toolbar or engine overlay may cover the board. */
@media (max-width: 900px) {
    body:has(.analysis-lab) .shell { padding-bottom: 0; }
    body:has(.analysis-lab) .site-legal-footer { display: none; }
    main:has(.analysis-lab) {
        height: 100dvh;
        padding: 0 0 max(6px, env(safe-area-inset-bottom));
        overflow: hidden;
    }
    .analysis-lab {
        height: 100%;
        padding: 0;
    }
    .analysis-lab > .analysis-lab__intro {
        display: flex;
        flex: 0 0 58px;
        min-height: 58px;
        align-items: center;
        justify-content: center;
        margin: 0;
        padding: 3px 72px 3px;
        border-bottom: 1px solid var(--theme-border);
        background: var(--theme-surface);
        text-align: center;
    }
    .analysis-lab__intro > div:first-child { min-width: 0; }
    .analysis-lab__intro .workspace-kicker { display: none; }
    .analysis-lab__intro h1 {
        overflow: hidden;
        font-family: "Archivo", "Segoe UI", sans-serif;
        font-size: 1.12rem;
        font-weight: 850;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .analysis-lab__intro .analysis-replay-summary { display: none; }
    .analysis-lab__workspace {
        display: flex;
        flex: 1 1 auto;
        min-height: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }
    .analysis-lab .analysis-board-stage,
    .analysis-lab--replay .analysis-board-stage {
        width: min(calc(100vw - 18px), calc(100dvh - 326px - env(safe-area-inset-bottom)));
        max-width: 38rem;
        flex: 0 0 auto;
        align-self: center;
        justify-self: auto;
        margin: 4px 0 2px;
    }
    .analysis-lab .analysis-board-row {
        display: flex;
        align-items: stretch;
        gap: 3px;
    }
    .analysis-lab .analysis-board-wrap { padding: 0 0 17px 0; }
    .analysis-lab .analysis-eval {
        display: flex;
        width: 18px;
        min-width: 18px;
        padding-bottom: 17px;
    }
    .analysis-lab .analysis-eval__score { font-size: .55rem; }
    .analysis-lab .analysis-eval__track { min-height: 0; }
    .analysis-lab .analysis-console {
        display: flex;
        width: 100%;
        min-height: 0;
        max-height: none;
        flex: 1 1 0;
        flex-direction: column;
        margin: 0;
        overflow: hidden;
        border: 1px solid var(--theme-border);
        border-bottom: 0;
        border-radius: 16px 16px 0 0;
        background: var(--theme-surface);
    }
    .analysis-lab .analysis-console__head {
        min-height: 48px;
        flex: 0 0 48px;
        padding: 2px 10px;
    }
    .analysis-lab .analysis-console__actions { justify-content: space-between; }
    .analysis-lab .analysis-icon-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 3px 8px;
        color: var(--theme-title);
        background: var(--theme-input);
        border: 1px solid var(--theme-border);
    }
    .analysis-lab .analysis-engine {
        display: grid;
        min-height: 44px;
        flex: 0 0 44px;
        grid-template-columns: auto minmax(0, 1fr);
        padding: 1px 10px;
    }
    .analysis-lab .analysis-tree-section {
        display: flex;
        min-height: 0;
        flex: 1 1 auto;
        flex-direction: column;
        order: 0;
        padding: 0;
        border-top: 0;
    }
    .analysis-lab .analysis-section-title {
        min-height: 48px;
        flex: 0 0 48px;
        justify-content: center;
        padding: 2px 10px;
        margin: 0;
    }
    .analysis-lab .analysis-section-actions {
        width: 100%;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: stretch;
        gap: 8px;
    }
    .analysis-lab .analysis-text-btn {
        min-height: 44px;
        flex: 1 1 0;
        padding: 4px 7px;
        color: var(--theme-title);
        background: var(--theme-input);
        border: 1px solid var(--theme-border);
        font-size: .75rem;
        white-space: nowrap;
    }
    .analysis-lab .analysis-review-summary {
        display: flex;
        max-height: 38px;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: 2px 8px;
        margin: 0;
    }
    .analysis-lab .analysis-tree {
        display: block;
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
        overflow: auto;
        padding: 5px 10px;
    }
    .analysis-lab .analysis-nav {
        display: flex;
        min-height: 48px;
        flex: 0 0 48px;
        justify-content: space-around;
        gap: 2px;
        padding: 2px 7px;
        border-top: 1px solid var(--theme-border);
    }
    .analysis-lab .analysis-nav button {
        display: grid;
        width: 44px;
        min-width: 44px;
        height: 44px;
        place-items: center;
        padding: 0;
        border: 1px solid var(--theme-border);
        background: var(--theme-input);
    }
    .analysis-lab .analysis-console__foot {
        min-height: 48px;
        flex: 0 0 48px;
        gap: 7px;
        padding: 2px 8px;
    }
    .analysis-lab .analysis-console__foot button { min-height: 44px; font-size: .7rem; }
    .analysis-lab .analysis-player { display: none; }
}

/* Compact entry screens: choices first, gameplay close to the first fold. */
@media (max-width: 900px) {
    .tactical-progress-expand { display: none; }
    .puzzle-journey-room .tactical-progress-card {
        position: relative;
        gap: .3rem;
        padding: .55rem .65rem 2.45rem !important;
    }
    .puzzle-journey-room .tactical-progress-card__identity { min-height: 48px; }
    .puzzle-journey-room .tactical-progress-card__crest { width: 36px; height: 36px; }
    .puzzle-journey-room .tactical-progress-card__identity h2 { font-size: 1.15rem; }
    .puzzle-journey-room .tactical-progress-card__meter,
    .puzzle-journey-room .tactical-progress-card__stats { display: none; }
    .puzzle-journey-room .tactical-progress-card.is-expanded .tactical-progress-card__meter,
    .puzzle-journey-room .tactical-progress-card.is-expanded .tactical-progress-card__stats { display: grid; }
    .puzzle-journey-room .tactical-progress-expand {
        position: absolute;
        right: .65rem;
        bottom: .35rem;
        left: .65rem;
        display: flex;
        min-height: 31px;
        align-items: center;
        justify-content: space-between;
        padding: 0 .55rem;
        border: 0;
        border-radius: 7px;
        color: var(--theme-accent-text);
        background: var(--theme-accent-soft);
        font-size: .75rem;
        font-weight: 800;
        cursor: pointer;
    }
    .puzzle-journey-room .tactical-progress-card.is-expanded .tactical-progress-expand span:last-child { transform: rotate(180deg); }
    .puzzle-journey-room .puzzle-tactical-modes {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px;
    }
    .puzzle-journey-room .puzzle-tactical-modes > a {
        display: flex;
        min-width: 0;
        min-height: 61px;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 2px;
        padding: 4px 2px;
        text-align: center;
    }
    .puzzle-journey-room .puzzle-tactical-modes__icon {
        width: 26px;
        height: 26px;
        flex: 0 0 26px;
    }
    .puzzle-journey-room .puzzle-tactical-modes__icon img,
    .puzzle-journey-room .puzzle-tactical-modes__icon svg { width: 24px; height: 24px; }
    .puzzle-journey-room .puzzle-tactical-modes > a > span:nth-child(2) { display: block; }
    .puzzle-journey-room .puzzle-tactical-modes strong {
        display: block;
        overflow: visible;
        font-size: .64rem;
        line-height: 1.1;
        white-space: normal;
    }
    .puzzle-journey-room .puzzle-board-stage { width: min(100%, calc(100dvh - 345px)); }
    /* The next exercise must stay reachable after solving, even on a short
       tablet viewport with a full-size board and an expanded reward recap. */
    .puzzle-journey-room:has([data-next-puzzle]:not([hidden])) .puzzle-next-action {
        position: fixed;
        right: max(10px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
        left: max(10px, env(safe-area-inset-left));
        z-index: 32;
        width: auto;
        min-height: 48px;
        box-shadow: 0 8px 28px color-mix(in srgb, var(--theme-title) 28%, transparent);
    }
    .puzzle-journey-room:has([data-next-puzzle]:not([hidden])) .puzzle-quest-card {
        padding-bottom: calc(5rem + env(safe-area-inset-bottom));
    }
    @media (max-height: 850px) {
        .puzzle-journey-room > .puzzle-page-header { display: none; }
        .puzzle-journey-room .tactical-progress-card {
            min-height: 54px;
            padding: .3rem 4.25rem .3rem .45rem !important;
        }
        .puzzle-journey-room .tactical-progress-card__identity { min-height: 42px; }
        .puzzle-journey-room .tactical-progress-card__crest { width: 30px; height: 30px; }
        .puzzle-journey-room .tactical-progress-card__identity .workspace-kicker,
        .puzzle-journey-room .tactical-progress-card__rating-mark,
        .puzzle-journey-room .tactical-progress-card__rating-band,
        .puzzle-journey-room .tactical-progress-card__rating-copy small { display: none; }
        .puzzle-journey-room .tactical-progress-expand {
            right: .4rem;
            bottom: .35rem;
            left: auto;
            width: 3.4rem;
            min-height: 38px;
            justify-content: center;
        }
        .puzzle-journey-room .tactical-progress-expand span:first-child { font-size: 0; }
        .puzzle-journey-room .tactical-progress-expand span:first-child::after { content: 'Más'; font-size: .75rem; }
        .puzzle-journey-room .tactical-progress-expand span:last-child { display: none; }
        .puzzle-journey-room .puzzle-tactical-modes > a { min-height: 45px; }
        .puzzle-journey-room .puzzle-tactical-modes__icon { width: 18px; height: 18px; flex-basis: 18px; }
        .puzzle-journey-room .puzzle-tactical-modes__icon img,
        .puzzle-journey-room .puzzle-tactical-modes__icon svg { width: 18px; height: 18px; }
        .puzzle-journey-room .puzzle-board-stage { width: min(100%, calc(100dvh - 480px)); }
        .puzzle-journey-room .puzzle-board-foot { min-height: 24px; padding: .15rem .3rem; }
        .puzzle-journey-room .puzzle-quest-card { padding: .45rem .6rem; }
        .puzzle-journey-room .puzzle-card-topline,
        .puzzle-journey-room .puzzle-reward-preview { display: none; }
        .puzzle-journey-room .puzzle-quest-card .card-title { margin: 0 0 .2rem; font-size: 1rem; }
        .puzzle-journey-room .puzzle-status { min-height: 32px; margin: 0 0 .3rem; padding: .3rem .55rem; }
        .puzzle-journey-room .puzzle-actions { gap: .3rem; }
        .puzzle-journey-room .puzzle-actions .btn { min-height: 40px; }
        .puzzle-journey-room:has([data-next-puzzle]:not([hidden])) .puzzle-quest-card {
            padding-bottom: calc(5rem + env(safe-area-inset-bottom));
        }
    }
    @media (min-width: 410px) and (max-height: 850px) {
        .puzzle-journey-room .puzzle-board-stage { max-width: calc(100% - 24px); }
    }

    /* A decorative board must not push the real play choices below the fold. */
    body:has(.play-room) main { padding-top: max(3.7rem, env(safe-area-inset-top)); }
    .play-room-intro { min-height: 0; margin-bottom: .4rem; }
    .play-room-intro .play-room-kicker { display: none; }
    .play-room-intro h1 { font-size: 1.45rem; line-height: 1.1; }
    .play-room-layout:not(:has([data-play-board]:not([hidden]))) .play-board-stage { display: none; }
    .play-room .play-panel-setup .play-panel-body { padding-block: .75rem; }
    .play-room .play-auth-number { display: none; }
    .play-room .play-auth-gate { padding-block: .6rem; }

    .rush-page .rush-lobby { margin-top: .45rem; }
    .rush-page .rush-hero { gap: .55rem; padding: .65rem; }
    .rush-page .rush-launch-mark { width: 2.75rem; border-radius: .6rem; }
    .rush-page .rush-hero-copy h1 { font-size: 1.55rem; }
    .rush-page .rush-hero-copy > p:last-child { display: none; }
    .rush-page .rush-hero-actions { gap: .35rem; }
    .rush-page .rush-mode-section { padding: .65rem; }
    .rush-page .rush-mode-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; }
    .rush-page .rush-mode-card,
    .rush-page .rush-mode-card.is-selected,
    .rush-page .rush-mode-card:last-child {
        display: grid;
        min-height: 78px;
        grid-column: auto;
        grid-template-columns: minmax(0, 1fr);
        gap: 2px;
        padding: .5rem .6rem;
    }
    .rush-page .rush-mode-card__top { grid-row: auto; justify-content: flex-start; gap: .25rem; }
    .rush-page .rush-mode-glyph { width: 26px; }
    .rush-page .rush-mode-clock,
    .rush-page .rush-mode-card.is-selected .rush-mode-clock { font-size: 1.4rem; }
    .rush-page .rush-mode-card > strong { font-size: .78rem; }
    .rush-page .rush-mode-records { display: none; }
    .rush-page .rush-lobby-action { padding-top: .45rem; margin-top: .45rem; }

    .battle-page:not(.battle-active-page) .battle-arena { gap: .45rem; padding: .7rem; }
    .battle-page:not(.battle-active-page) .battle-copy h1 { font-size: 1.55rem; }
    .battle-page:not(.battle-active-page) .battle-player-card { min-height: 0; padding: .4rem; }
    .battle-page:not(.battle-active-page) .battle-lobby-grid { gap: .5rem; }
    .battle-page:not(.battle-active-page) .battle-development-card { padding: .65rem; }

    /* Extensive filters and bot rosters scroll inside their own work area. */
    html:has(.custom-trainer-room),
    html:has(.bot-lobby-workspace),
    body:has(.custom-trainer-room),
    body:has(.bot-lobby-workspace) { height: 100dvh; overflow: hidden; }
    body:has(.custom-trainer-room) .shell,
    body:has(.bot-lobby-workspace) .shell { padding-bottom: 0; }
    body:has(.custom-trainer-room) .site-legal-footer,
    body:has(.bot-lobby-workspace) .site-legal-footer { display: none; }
    main:has(.custom-trainer-room),
    main:has(.bot-lobby-workspace) {
        height: var(--mobile-viewport-height, 100dvh);
        min-height: 0;
        overflow: hidden;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
    .custom-trainer-room,
    .bot-lobby-workspace {
        display: flex;
        height: 100%;
        min-height: 0;
        flex-direction: column;
    }
    .custom-trainer-room > .puzzle-page-header,
    .custom-trainer-room > .puzzle-nav-mobile,
    .bot-lobby-workspace > .bot-lobby-intro { flex: 0 0 auto; }
    .custom-trainer-room .custom-config-card,
    .custom-trainer-room .custom-training {
        min-height: 0;
        flex: 1 1 auto;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .custom-trainer-room .custom-config-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        padding: .6rem 0 max(.35rem, env(safe-area-inset-bottom));
        background: var(--theme-surface);
    }
    .bot-lobby-workspace .bot-lobby-shell {
        display: flex;
        min-height: 0;
        flex: 1 1 auto;
        flex-direction: column;
        gap: .45rem;
        overflow: hidden;
    }
    .bot-lobby-workspace .bot-roster {
        min-height: 150px;
        max-height: 31dvh;
        flex: 0 1 31dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .bot-lobby-workspace .bot-brief {
        min-height: 0;
        flex: 1 1 auto;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .bot-lobby-workspace .bot-studio-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: var(--theme-surface);
    }

    /* During Rush the clock, board and essential actions share one screen. */
    html:has(.rush-page [data-rush-game]:not([hidden])),
    body:has(.rush-page [data-rush-game]:not([hidden])) {
        height: 100dvh;
        overflow: hidden;
    }
    body:has(.rush-page [data-rush-game]:not([hidden])) .shell { padding-bottom: 0; }
    body:has(.rush-page [data-rush-game]:not([hidden])) .site-legal-footer { display: none; }
    body:has(.rush-page [data-rush-game]:not([hidden])) main {
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
        padding: max(3.7rem, env(safe-area-inset-top)) 8px max(4px, env(safe-area-inset-bottom));
    }
    .rush-page:has([data-rush-game]:not([hidden])) {
        display: flex;
        height: 100%;
        min-height: 0;
        flex-direction: column;
        padding: 0;
    }
    .rush-page:has([data-rush-game]:not([hidden])) > .puzzle-nav-mobile { display: none; }
    .rush-page [data-rush-game]:not([hidden]) { min-height: 0; flex: 1 1 auto; }
    .rush-page [data-rush-game]:not([hidden]) .rush-play-layout {
        display: flex;
        height: 100%;
        min-height: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 3px;
    }
    .rush-page [data-rush-game]:not([hidden]) .rush-console-head {
        min-height: 64px;
        flex: 0 0 64px;
        order: 0;
        margin: 0;
        padding: .2rem .7rem;
        border-radius: 11px;
    }
    .rush-page [data-rush-game]:not([hidden]) .rush-console-head > div {
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 3px 10px;
    }
    .rush-page [data-rush-game]:not([hidden]) .rush-timer { margin-top: 0; font-size: 1.7rem; }
    .rush-page [data-rush-game]:not([hidden]) .rush-score strong { font-size: 1.45rem; line-height: 1; }
    .rush-page [data-rush-game]:not([hidden]) .rush-score > span { display: none; }
    .rush-page [data-rush-game]:not([hidden]) .rush-board-column {
        width: min(100%, calc(100dvh - 350px - env(safe-area-inset-bottom)));
        min-height: 0;
        flex: 0 0 auto;
        order: 1;
        align-self: center;
        gap: 2px;
    }
    .rush-page [data-rush-game]:not([hidden]) .rush-console {
        min-height: 0;
        flex: 1 1 auto;
        order: 2;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .rush-page [data-rush-game]:not([hidden]) .rush-console-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        display: grid;
        min-height: 48px;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 6px;
        padding: 3px 6px;
        background: var(--rush-surface);
    }
    .rush-page [data-rush-game]:not([hidden]) .rush-console-session { min-height: 42px; padding: 3px 8px; }
    .rush-page [data-rush-game]:not([hidden]) .rush-lives,
    .rush-page [data-rush-game]:not([hidden]) .rush-puzzle-heading { padding: 3px 8px; }
    .rush-page [data-rush-game]:not([hidden]) .rush-abandon { font-size: .72rem; white-space: nowrap; }

    /* Puzzle Duel follows the same board-first viewport as Sprint. The
       scoreboard remains independently scrollable for custom 3–10 rooms. */
    html:has(.battle-active-page [data-battle-match]:not([hidden])),
    body:has(.battle-active-page [data-battle-match]:not([hidden])) {
        height: 100dvh;
        overflow: hidden;
    }
    body:has(.battle-active-page [data-battle-match]:not([hidden])) .shell { padding-bottom: 0; }
    body:has(.battle-active-page [data-battle-match]:not([hidden])) .site-legal-footer { display: none; }
    body:has(.battle-active-page [data-battle-match]:not([hidden])) main {
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
        padding: max(3.7rem, env(safe-area-inset-top)) 6px max(4px, env(safe-area-inset-bottom));
    }
    .battle-active-page:has([data-battle-match]:not([hidden])) {
        display: flex;
        height: 100%;
        min-height: 0;
        flex-direction: column;
        padding: 0;
    }
    .battle-active-page:has([data-battle-match]:not([hidden])) > .battle-match-heading { display: none; }
    .battle-active-page [data-battle-match]:not([hidden]) {
        display: flex;
        min-height: 0;
        flex: 1 1 auto;
        flex-direction: column;
        align-items: stretch;
        gap: 3px;
    }
    .battle-active-page [data-battle-match]:not([hidden]) > .battle-round-summary {
        min-height: 54px;
        flex: 0 0 54px;
        order: 0;
    }
    .battle-active-page [data-battle-match]:not([hidden]) .battle-clock,
    .battle-active-page [data-battle-match]:not([hidden]) .battle-problem-count { min-height: 52px; }
    .battle-active-page [data-battle-match]:not([hidden]) .battle-board-column {
        width: min(100%, calc(100dvh - 390px - env(safe-area-inset-bottom)));
        min-height: 0;
        flex: 0 0 auto;
        order: 1;
        align-self: center;
        gap: 3px;
    }
    .battle-active-page [data-battle-match]:not([hidden]) .battle-participant {
        min-height: 38px;
        padding: 2px 5px;
    }
    .battle-active-page [data-battle-match]:not([hidden]) .battle-participant-copy > span { display: none; }
    .battle-active-page [data-battle-match]:not([hidden]) .battle-match-panel {
        min-height: 0;
        flex: 1 1 auto;
        order: 2;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .battle-active-page [data-battle-match]:not([hidden]) .battle-abandon {
        position: sticky;
        bottom: 0;
        z-index: 2;
        background: var(--theme-surface);
    }
}
/* En Problemas, los tres indicadores compactos siempre quedan visibles. */
@media (max-width: 900px) {
    .puzzle-journey-room .tactical-progress-card__meter {
        display: grid;
    }
    .puzzle-journey-room .tactical-progress-card {
        min-height: 0;
        gap: .45rem;
        padding: .5rem .65rem !important;
    }
    .puzzle-journey-room .tactical-progress-card__stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: .2rem;
    }
    .puzzle-journey-room .tactical-progress-card__stats dd { font-size: clamp(.76rem, 3.2vw, .88rem); }
    .puzzle-journey-room .tactical-progress-card__rating-copy small { display: block; }
}
