/*
 * PARTIDAS POR POSICIÓN — interfaz compartida entre Workbench y móvil.
 * La lógica vive en position-game-search.js; este archivo solo define su capa visual.
 */

.position-game-search-pane,
.position-game-search-host,
.position-game-search-view,
.position-game-search-overlay,
.position-game-search-dialog {
    box-sizing: border-box;
}

.position-game-search-pane[hidden],
.position-game-search-overlay[hidden] {
    display: none !important;
}

.position-game-preview-dock[hidden] {
    display: none !important;
}

.position-game-search-pane {
    min-width: 0;
    min-height: 0;
}

.position-game-search-host {
    container-type: inline-size;
    width: 100%;
    min-width: 0;
    min-height: 0;
}

.position-game-search-view {
    --pgs-surface: var(--theme-bg-primary, #15171b);
    --pgs-card: var(--theme-bg-secondary, #202228);
    --pgs-soft: color-mix(in srgb, var(--theme-bg-secondary, #202228) 82%, transparent);
    --pgs-border: color-mix(in srgb, var(--theme-border, #7d6928) 72%, transparent);
    --pgs-border-strong: color-mix(in srgb, var(--theme-accent-primary, #d4af37) 64%, transparent);
    --pgs-accent: var(--theme-accent-primary, #d4af37);
    --pgs-accent-contrast: var(--theme-text-on-accent, #0b0c0e);
    --pgs-text: var(--theme-text-primary, #f4f1e8);
    --pgs-muted: var(--theme-text-secondary, #aaa69a);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-width: 0;
    flex: 1 1 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scrollbar-color: var(--pgs-accent) transparent;
    padding: 10px;
    color: var(--pgs-text);
    font-family: Poppins, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.position-game-search__intro {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--pgs-border);
    border-radius: 14px;
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--pgs-accent) 9%, transparent), transparent 55%),
        var(--pgs-soft);
}

/* Un solo recorrido vertical: la cabecera sale del camino al buscar entre
   partidas, sin encerrar la lista en una ventanita dentro del panel. */
.position-game-search-view > * {
    flex-shrink: 0;
}

.position-game-search__eyebrow,
.position-game-search-dialog__eyebrow {
    display: block;
    margin: 0 0 3px;
    color: var(--pgs-accent, var(--theme-accent-primary, #d4af37));
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .12em;
    line-height: 1.2;
    text-transform: uppercase;
}

.position-game-search__intro h2 {
    margin: 0;
    color: var(--pgs-text);
    font-size: clamp(15px, 1.45vw, 20px);
    line-height: 1.22;
}

.position-game-search__intro p {
    grid-column: 1 / -1;
    margin: 0;
    color: var(--pgs-muted);
    font-size: 11px;
    line-height: 1.5;
}

.position-game-search__source {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--pgs-border);
    border-radius: 999px;
    background: var(--pgs-card);
    color: var(--pgs-muted);
    font-size: 9px;
    font-weight: 700;
    white-space: nowrap;
}

.position-game-search__source-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
    min-width: 152px;
    padding: 3px;
    border: 1px solid var(--pgs-border);
    border-radius: 11px;
    background: color-mix(in srgb, var(--pgs-card) 84%, transparent);
}

.position-game-search__source-switcher button {
    min-width: 0;
    min-height: 34px;
    padding: 6px 9px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--pgs-muted);
    font: inherit;
    font-size: 9px;
    font-weight: 750;
    cursor: pointer;
}

.position-game-search__source-switcher button.is-active,
.position-game-search__source-switcher button[aria-pressed="true"] {
    border-color: var(--pgs-border-strong);
    background: color-mix(in srgb, var(--pgs-accent) 14%, var(--pgs-card));
    color: var(--pgs-accent);
    box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--pgs-accent) 56%, transparent);
}

.position-game-search__source::before {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pgs-accent);
    box-shadow: 0 0 10px color-mix(in srgb, var(--pgs-accent) 65%, transparent);
    content: '';
}

.position-game-search__refresh,
.position-game-search__retry,
.position-game-search__load-more,
.position-game-search__restore,
.position-game-card__action {
    min-height: 40px;
    border: 1px solid var(--pgs-border-strong);
    border-radius: 10px;
    background: color-mix(in srgb, var(--pgs-accent) 10%, var(--pgs-card));
    color: var(--pgs-accent);
    font: inherit;
    font-size: 10px;
    font-weight: 750;
    line-height: 1.25;
    cursor: pointer;
}

.position-game-card--skeleton {
    min-height: 116px;
    pointer-events: none;
}

.position-game-card__skeleton-line {
    display: block;
    width: 72%;
    height: 12px;
    border-radius: 999px;
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--pgs-muted) 10%, transparent),
        color-mix(in srgb, var(--pgs-accent) 18%, transparent),
        color-mix(in srgb, var(--pgs-muted) 10%, transparent));
    background-size: 220% 100%;
    animation: positionGameSearchSkeleton 1.25s ease-in-out infinite;
}

.position-game-card__skeleton-line.is-wide { width: 92%; height: 16px; }
.position-game-card__skeleton-line.is-short { width: 46%; }

.position-game-search__refresh {
    padding: 7px 10px;
}

.position-game-search__status {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 44px;
    margin: 0;
    padding: 9px 11px;
    border: 1px solid var(--pgs-border);
    border-radius: 11px;
    background: var(--pgs-soft);
    color: var(--pgs-muted);
    font-size: 10px;
    line-height: 1.4;
}

.position-game-search__status[hidden] {
    display: none !important;
}

.position-game-search__status.is-error {
    border-color: color-mix(in srgb, #ef5350 58%, var(--pgs-border));
    color: color-mix(in srgb, #ef5350 78%, var(--pgs-text));
}

.position-game-search__status.is-stale {
    border-color: var(--pgs-border-strong);
    color: var(--pgs-text);
}

.position-game-search__retry {
    flex: 0 0 auto;
    min-height: 36px;
    margin-left: auto;
    padding: 6px 10px;
}

.position-game-search__retry[hidden] {
    display: none !important;
}

.position-game-search__spinner {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border: 2px solid color-mix(in srgb, var(--pgs-accent) 23%, transparent);
    border-top-color: var(--pgs-accent);
    border-radius: 50%;
    animation: positionGameSearchSpin .75s linear infinite;
}

.position-game-search__summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 22px;
    color: var(--pgs-muted);
    font-size: 10px;
}

.position-game-search__summary[hidden] {
    display: none !important;
}

.position-game-search__summary strong {
    color: var(--pgs-text);
}

.position-game-search__results {
    display: grid;
    align-content: start;
    gap: 8px;
    min-height: 0;
    margin: 0;
    padding: 0 2px 2px 0;
    overflow: visible;
    list-style: none;
}

.position-game-card {
    display: grid;
    gap: 8px;
    min-width: 0;
    padding: 11px;
    border: 1px solid var(--pgs-border);
    border-radius: 13px;
    background: var(--pgs-card);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .12);
}

.position-game-card__players {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 3px 8px;
    min-width: 0;
}

.position-game-card__player {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
    color: var(--pgs-text);
    font-size: 11px;
    font-weight: 700;
}

.position-game-card__player span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.position-game-card__elo {
    flex: 0 0 auto;
    color: var(--pgs-muted);
    font-size: 9px;
    font-weight: 600;
}

.position-game-card__result {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: stretch;
    display: grid;
    place-items: center;
    min-width: 44px;
    padding: 5px 7px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--pgs-accent) 10%, transparent);
    color: var(--pgs-accent);
    font-family: "Roboto Mono", Consolas, monospace;
    font-size: 10px;
    font-weight: 800;
}

.position-game-card__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 9px;
    min-width: 0;
    color: var(--pgs-muted);
    font-size: 9px;
    line-height: 1.35;
}

.position-game-card__meta span {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.position-game-card__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.position-game-card__action {
    min-width: 0;
    padding: 7px 8px;
}

.position-game-card__action--open {
    border-color: var(--pgs-accent);
    background: var(--pgs-accent);
    color: var(--pgs-accent-contrast);
}

.position-game-search__footer {
    display: flex;
    justify-content: center;
}

.position-game-search__load-more {
    width: 100%;
    padding: 8px 12px;
}

.position-game-search__load-more[hidden] {
    display: none !important;
}

.position-game-search__preview-bar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 9px;
    padding: 9px 10px;
    border: 1px solid var(--pgs-border-strong);
    border-radius: 12px;
    background: color-mix(in srgb, var(--pgs-accent) 12%, var(--pgs-surface));
    box-shadow: 0 12px 28px rgba(0, 0, 0, .24);
}

.position-game-search__preview-bar[hidden] {
    display: none !important;
}

.position-game-search__preview-copy {
    min-width: 0;
}

.position-game-search__preview-copy strong,
.position-game-search__preview-copy span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.position-game-search__preview-copy strong {
    color: var(--pgs-text);
    font-size: 10px;
}

.position-game-search__preview-copy span {
    color: var(--pgs-muted);
    font-size: 9px;
}

.position-game-search__preview-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.position-game-search__restore {
    width: 100%;
    min-height: 36px;
    padding: 6px 9px;
}

.position-game-search__empty {
    display: grid;
    place-items: center;
    gap: 5px;
    min-height: 132px;
    padding: 18px;
    border: 1px dashed var(--pgs-border);
    border-radius: 13px;
    color: var(--pgs-muted);
    text-align: center;
}

.position-game-search__empty[hidden] {
    display: none !important;
}

.position-game-search__empty strong {
    color: var(--pgs-text);
    font-size: 12px;
}

.position-game-search__empty span {
    font-size: 10px;
    line-height: 1.45;
}

.position-game-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 21430;
    display: grid;
    align-items: end;
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    background: rgba(2, 4, 8, .7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.position-game-search-dialog {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid var(--theme-border, #6d5a22);
    border-radius: 20px;
    background: var(--theme-bg-primary, #15171b);
    color: var(--theme-text-primary, #f4f1e8);
    box-shadow: 0 28px 80px rgba(0, 0, 0, .62), 0 0 32px var(--theme-shadow-glow, rgba(212, 175, 55, .12));
}

.position-game-search-dialog__header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 14px;
    border-bottom: 1px solid color-mix(in srgb, var(--theme-border, #6d5a22) 65%, transparent);
    background: var(--theme-bg-secondary, #202228);
}

.position-game-search-dialog__header h2 {
    margin: 0;
    color: var(--theme-text-primary, #f4f1e8);
    font: 750 16px/1.25 Poppins, system-ui, sans-serif;
}

.position-game-search-dialog__close {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--theme-border, #6d5a22);
    border-radius: 11px;
    background: color-mix(in srgb, var(--theme-bg-primary, #15171b) 88%, transparent);
    color: var(--theme-accent-primary, #d4af37);
    font: 400 25px/1 system-ui, sans-serif;
}

.position-game-search-dialog__header-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

.position-game-search-dialog__back {
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--theme-border, #6d5a22);
    border-radius: 10px;
    background: color-mix(in srgb, var(--theme-accent-primary, #d4af37) 10%, var(--theme-bg-secondary, #202228));
    color: var(--theme-text-primary, #f4f1e8);
    font: inherit;
    font-size: 11px;
    font-weight: 750;
}

.position-game-search-dialog > .position-game-search-host {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

html:has(> body.position-game-search-modal-open),
body.position-game-search-modal-open {
    overflow: hidden !important;
}

.position-game-preview-dock {
    position: sticky;
    top: 0;
    z-index: 4;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 7px;
    width: auto;
    max-width: none;
    margin: 8px 10px 0;
    padding: 9px;
    border: 1px solid color-mix(in srgb, var(--theme-accent-primary, #d4af37) 64%, transparent);
    border-radius: 14px;
    background: color-mix(in srgb, var(--theme-bg-primary, #15171b) 95%, transparent);
    color: var(--theme-text-primary, #f4f1e8);
    box-shadow: 0 18px 46px rgba(0, 0, 0, .5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    font-family: Poppins, system-ui, sans-serif;
}

.position-game-preview-dock__copy {
    grid-column: 1 / -1;
    min-width: 0;
}

.position-game-preview-dock__copy strong,
.position-game-preview-dock__copy span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.position-game-preview-dock__copy strong {
    color: var(--theme-accent-primary, #d4af37);
    font-size: 10px;
}

.position-game-preview-dock__copy span {
    color: var(--theme-text-secondary, #aaa69a);
    font-size: 9px;
}

.position-game-preview-dock button {
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid var(--theme-border, #6d5a22);
    border-radius: 9px;
    background: color-mix(in srgb, var(--theme-accent-primary, #d4af37) 10%, var(--theme-bg-secondary, #202228));
    color: var(--theme-accent-primary, #d4af37);
    font: 750 9px/1.2 Poppins, system-ui, sans-serif;
}

.position-game-preview-tools {
    display: none;
}

/* La consulta de una partida prioriza la lectura. Solo afecta a la vista
   previa en Workbench horizontal; el PGN propio y el modo móvil no cambian. */
@media (min-width: 769px) and (orientation: landscape) {
    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane > .workbench-pgn-heading {
        display: none !important;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #positionGamePreviewDock {
        position: relative;
        top: auto;
        gap: 6px;
        margin: 6px 8px 0;
        padding: 7px;
        box-shadow: none;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #positionGamePreviewDockTitle {
        display: none;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #positionGamePreviewDock button {
        min-height: 44px;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane > #pgn-metadata {
        margin: 6px 8px 0;
        padding: 0;
        font-size: 11px;
        line-height: 1.4;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] .pgn-meta-players {
        display: flex;
        align-items: baseline;
        flex-wrap: wrap;
        gap: 3px 5px;
        font-size: 11px;
        line-height: 1.4;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] .pgn-meta-info {
        font-size: 10px;
        line-height: 1.4;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane > #pgn-viewer {
        flex: 1 1 0 !important;
        width: auto !important;
        min-width: 0 !important;
        align-self: stretch;
        margin: 8px 8px 0;
        padding: 9px 10px;
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #positionGamePreviewTools:not([hidden]) {
        display: flex;
        flex: 0 0 auto;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        min-height: 44px;
        margin: 6px 8px 8px;
        padding: 8px 10px;
        border: 1px solid var(--theme-border);
        border-radius: 9px;
        background: var(--theme-bg-secondary);
        color: var(--theme-text-secondary);
        font: 600 11px/1.3 Poppins, system-ui, sans-serif;
        cursor: pointer;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #positionGamePreviewTools:focus-visible {
        outline: 2px solid var(--theme-accent-primary);
        outline-offset: -3px;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #positionGamePreviewTools[aria-expanded="true"] svg {
        transform: rotate(180deg);
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane > #positionGamePreviewTools[aria-expanded="false"] ~ .pgn-toolbar {
        display: none !important;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane > .pgn-toolbar {
        margin: 0 8px 8px !important;
        max-height: 96px;
        overflow-y: auto;
        touch-action: pan-y;
        overscroll-behavior-y: contain;
    }

    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane:has(> #positionGamePreviewTools[aria-expanded="true"]) > .workbench-pgn-heading {
        display: flex !important;
        padding: 6px 8px;
    }
}

@media (min-width: 769px) and (orientation: landscape) and (max-height: 650px) {
    html[data-workbench="v3"] body[data-position-game-preview="true"] #workbenchPgnPane:has(> #positionGamePreviewTools[aria-expanded="true"]) > .workbench-pgn-heading {
        display: none !important;
    }
}

.mobile-position-games-launcher {
    display: inline-grid;
    place-items: center;
    width: 44px;
    min-width: 44px;
    height: 44px !important;
    min-height: 44px !important;
    padding: 6px !important;
    color: var(--theme-accent-primary, #d4af37) !important;
}

.mobile-position-games-launcher svg {
    display: block;
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.mobile-position-games-launcher[hidden] {
    display: none !important;
}

.mobile-pgn-tools-icon {
    display: none;
    width: 19px;
    height: 19px;
    fill: currentColor;
}

html[data-theme="light-matrix"] .position-game-search-view {
    --pgs-accent-contrast: #fffefa;
}

.position-game-search__refresh:focus-visible,
.position-game-search__retry:focus-visible,
.position-game-search__load-more:focus-visible,
.position-game-search__restore:focus-visible,
.position-game-card__action:focus-visible,
.position-game-search__source-switcher button:focus-visible,
.position-game-preview-dock button:focus-visible,
.position-game-search-dialog__close:focus-visible,
.position-game-search-dialog__back:focus-visible,
.mobile-position-games-launcher:focus-visible {
    outline: 2px solid var(--theme-accent-primary, #d4af37);
    outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
    .position-game-card,
    .position-game-search__refresh,
    .position-game-search__retry,
    .position-game-search__load-more,
    .position-game-search__restore,
    .position-game-card__action,
    .position-game-search__source-switcher button,
    .position-game-preview-dock button,
    .position-game-search-dialog__close,
    .position-game-search-dialog__back,
    .mobile-position-games-launcher {
        transition: border-color .16s ease, background-color .16s ease, color .16s ease, transform .16s ease;
    }

    .position-game-card:hover {
        border-color: var(--pgs-border-strong);
    }

    .position-game-search button:hover:not(:disabled),
    .position-game-search-view button:hover:not(:disabled),
    .position-game-search-dialog__close:hover,
    .position-game-search-dialog__back:hover,
    .position-game-preview-dock button:hover:not(:disabled),
    .mobile-position-games-launcher:hover {
        transform: translateY(-1px);
    }
}

@media (min-width: 1181px),
       (min-width: 769px) and (orientation: landscape) {
    html[data-workbench="v3"] body .controls-container > #workbenchGamePane {
        display: none !important;
    }

    html[data-workbench="v3"] body .controls-container > #workbenchGamesPane {
        grid-area: workbench-pane !important;
        position: relative !important;
        inset: auto !important;
        z-index: auto !important;
        width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: 0 !important;
        overflow: hidden;
        border: 1px solid color-mix(in srgb, var(--theme-border, #6d5a22) 72%, transparent);
        border-radius: 14px;
        background: var(--theme-bg-primary, #15171b);
    }

    html[data-workbench="v3"] body .controls-container:not([data-workbench-tab="games"]) > #workbenchGamesPane {
        display: none !important;
    }

    html[data-workbench="v3"] body .controls-container[data-workbench-tab="games"] > #workbenchGamesPane {
        display: flex !important;
    }

    #positionGameSearchDesktopHost {
        display: flex;
        flex: 1 1 auto;
        overflow: hidden;
    }

}

@media (min-width: 1500px) and (max-height: 600px) and (orientation: landscape) {
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container {
        display: grid !important;
        grid-column: 3 / 5 !important;
        grid-template-areas:
            "workbench-tabs"
            "workbench-pane"
            "workbench-navigation"
            "workbench-fen" !important;
        grid-template-rows: auto minmax(0, 1fr) auto auto !important;
        width: calc(var(--panel-w-controles) + var(--panel-w-pgn) + var(--panel-gap)) !important;
        max-width: calc(var(--panel-w-controles) + var(--panel-w-pgn) + var(--panel-gap)) !important;
        overflow: hidden !important;
    }

    html[data-workbench="v3"] body:not([data-tablet-fix]) .controls-container > .workbench-tabs {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    }

    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container > #workbenchGamePane,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container > #workbenchPgnPane,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container > #stockfish-panel,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container > #workbenchMotorEmpty,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container > #workbenchTrainingPane {
        display: none !important;
    }

    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container > #workbenchPgnPane {
        position: relative !important;
        inset: auto !important;
        z-index: auto !important;
        flex: 1 1 auto !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        overflow: hidden !important;
    }

    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container[data-workbench-tab="pgn"] > #workbenchPgnPane,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container[data-workbench-tab="book"] > #workbenchPgnPane,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container[data-workbench-tab="training"] > #workbenchTrainingPane,
    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container[data-workbench-tab="engine"][data-engine-active="false"] > #workbenchMotorEmpty {
        display: flex !important;
    }

    html[data-workbench="v3"] body:not([data-tablet-fix]) .chess-layout > .controls-container[data-workbench-tab="engine"][data-engine-active="true"] > #stockfish-panel:not(.hidden) {
        display: block !important;
    }
}

@media (min-width: 1181px),
       (min-width: 769px) and (orientation: landscape) {
    #positionGameSearchMobileOverlay {
        display: none !important;
    }
}

@media (max-width: 768px),
       (min-width: 769px) and (max-width: 1180px) and (orientation: portrait) {
    .position-game-search-overlay {
        height: 100dvh;
        align-items: stretch;
        padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    }

    .position-game-preview-dock {
        margin: 0 0 8px;
        background: var(--theme-bg-primary, #15171b);
    }

    .position-game-search__refresh,
    .position-game-search__retry,
    .position-game-search__load-more,
    .position-game-search__restore,
    .position-game-card__action,
    .position-game-search__source-switcher button,
    .position-game-preview-dock button {
        min-height: 44px;
    }

    .position-game-search-dialog .position-game-search-view {
        padding: 9px;
    }

    .position-game-search-dialog .position-game-search__intro h2,
    .position-game-search-dialog .position-game-search__eyebrow,
    .position-game-search-dialog .position-game-search__intro p {
        display: none;
    }

    .position-game-search__intro {
        padding: 10px;
    }

    .position-game-search__intro h2 {
        font-size: 15px;
    }

    .position-game-search__intro p {
        font-size: 10px;
    }

    .position-game-card {
        padding: 10px;
    }
}

/* La anchura del panel, no la de la pantalla, determina la densidad. */
@container (max-width: 520px) {
    .position-game-search__intro {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding: 10px;
    }
    .position-game-search__intro > div:first-child {
        grid-column: 1 / -1;
        min-width: 0;
    }
    .position-game-search__intro h2 { font-size: 15px; }
    .position-game-search__eyebrow,
    .position-game-search__intro p { display: none; }
    .position-game-search__source {
        margin-top: 5px;
        white-space: normal;
    }
    .position-game-search__source-switcher {
        min-width: 0;
        width: 100%;
    }
    .position-game-search__source-switcher button { padding-inline: 4px; }
    .position-game-search__refresh { min-width: 0; }
}

@media (max-width: 380px) {
    .mobile-workspace__header-actions {
        gap: 3px !important;
    }

    .mobile-workspace__header-actions button {
        padding-inline: 7px !important;
    }

    #mobileWorkspacePgnTools {
        display: inline-grid;
        place-items: center;
        width: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 6px !important;
    }

    #mobileWorkspacePgnTools .mobile-pgn-tools-label {
        display: none;
    }

    #mobileWorkspacePgnTools .mobile-pgn-tools-icon {
        display: block;
    }

    .position-game-search__source {
        justify-self: start;
    }

    .position-game-search__source-switcher {
        width: 100%;
        min-width: 0;
    }

    .position-game-card__actions {
        grid-template-columns: 1fr;
    }

    .position-game-preview-dock {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .position-game-preview-dock__copy {
        grid-column: 1 / -1;
    }
}

@media (prefers-reduced-motion: reduce) {
    .position-game-search__spinner {
        animation-duration: 1.4s;
    }
}

@keyframes positionGameSearchSpin {
    to { transform: rotate(360deg); }
}

@keyframes positionGameSearchSkeleton {
    0% { background-position: 100% 0; }
    100% { background-position: -120% 0; }
}
