/* Phones get one compact card per game instead of a sideways-scrolling table.
   This restyles the existing table markup, so server-rendered rows and rows
   rendered by main.js look the same. Column order: title, handheld, docked,
   upgrade, version, sentiment, notes, date added, edit. */
@media (max-width: 768px) {
    .catalog-page .table-container {
        overflow: hidden;
    }

    .catalog-page #gamesTable,
    .catalog-page #gamesTable tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    /* The header shrinks to a sort bar, so the cloned sticky header is not needed. */
    .mobile-sticky-table-head,
    .mobile-sticky-table-head.is-visible {
        display: none;
    }

    .catalog-page #gamesTable thead {
        display: block;
        position: static;
        border-bottom: 1px solid var(--border);
    }

    .catalog-page #mainHeader {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .catalog-page #mainHeader th {
        display: none;
        position: static;
        background: transparent;
    }

    /* Only the title sort remains; cards don't show the date added. */
    .catalog-page #mainHeader #gameTh {
        display: block;
        width: auto !important;
        padding: 0.35rem 0.75rem;
        font-size: 0.6875rem;
    }

    .catalog-page #gamesTableBody tr.game-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.3rem 0.5rem;
        padding: 0.5rem 0.75rem 0.55rem;
        border: 0;
    }

    /* A faint hairline between cards that stops short of the card edges. */
    .catalog-page #gamesTableBody tr.game-row + tr.game-row {
        background-image: linear-gradient(rgba(204, 237, 235, 0.13), rgba(204, 237, 235, 0.13));
        background-position: top center;
        background-repeat: no-repeat;
        background-size: calc(100% - 1.5rem) 1px;
    }

    .catalog-page #gamesTableBody tr.game-row > td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        text-align: left;
    }

    /* Version, sentiment, notes, date and edit live on the game page. */
    .catalog-page #gamesTableBody tr.game-row > td:nth-child(n + 5) {
        display: none;
    }

    /* The title spans the card; the upgrade badge overlaps its right edge. */
    .catalog-page #gamesTableBody tr.game-row > td.game-title {
        grid-column: 1 / -1;
        grid-row: 1;
        position: static;
        min-width: 0;
        padding-right: 3.5rem;
        background: transparent;
        box-shadow: none;
        font-size: 0.875rem;
        line-height: 1.25;
    }

    /* "S2 Exclusive" is twice as wide as Free/Paid/None, so only those titles reserve more room. */
    .catalog-page #gamesTableBody tr.game-row:has(.upgrade-exclusive) > td.game-title {
        padding-right: 5.5rem;
    }

    .catalog-page #gamesTableBody tr.game-row > td:nth-child(4) {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        align-self: start;
    }

    .catalog-page #gamesTableBody .upgrade-badge {
        min-width: 0;
        padding: 0.1rem 0.4rem;
        font-size: 0.625rem;
    }

    /* A play-mode icon beside the chips replaces a text label line; the alt text keeps it readable. */
    .catalog-page #gamesTableBody tr.game-row > td:nth-child(2),
    .catalog-page #gamesTableBody tr.game-row > td:nth-child(3) {
        display: grid;
        grid-template-columns: 0.875rem minmax(0, 1fr);
        align-items: start;
        column-gap: 0.3rem;
    }

    .catalog-page #gamesTableBody tr.game-row > td:nth-child(2)::before,
    .catalog-page #gamesTableBody tr.game-row > td:nth-child(3)::before {
        content: "";
        width: 0.875rem;
        height: 1.375rem;
        background-color: var(--accent-warm);
        opacity: 0.8;
        -webkit-mask: var(--play-mode-icon) center / contain no-repeat;
        mask: var(--play-mode-icon) center / contain no-repeat;
    }

    .catalog-page #gamesTableBody tr.game-row > td:nth-child(2)::before {
        --play-mode-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='2' y='6' width='20' height='12' rx='3'/%3E%3Cpath d='M7 6v12M17 6v12'/%3E%3C/svg%3E");
        content: "";
        content: "" / "Handheld";
    }

    .catalog-page #gamesTableBody tr.game-row > td:nth-child(3)::before {
        --play-mode-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='2' y='3' width='20' height='14' rx='2'/%3E%3Cpath d='M12 17v4M7 21h10'/%3E%3C/svg%3E");
        content: "";
        content: "" / "Docked";
    }

    /* Capped so chips on wider phones and small tablets don't stretch the fps segment away. */
    .catalog-page #gamesTableBody .performance-mode-stack {
        width: 100%;
        max-width: 15rem;
        gap: 0.25rem;
    }

    .catalog-page #gamesTableBody .performance-mode-row {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.05rem;
    }

    .catalog-page #gamesTableBody .performance-mode-name {
        color: var(--text-secondary);
        opacity: 0.8;
        font-size: 0.625rem;
        line-height: 1.15;
    }

    .catalog-page #gamesTableBody .performance-mode-chip {
        grid-template-columns: minmax(0, 1fr) 3rem;
    }

    .catalog-page #gamesTableBody .performance-mode-chip-segment {
        min-height: 1.375rem;
        padding: 0.12rem 0.3rem;
        font-size: 0.75rem;
    }

    .catalog-page #gamesTableBody .performance-mode-chip-resolution-note {
        margin-top: 0;
        font-size: 0.625rem;
        line-height: 1.1;
    }

    .catalog-page #gamesTableBody .missing-data-badge {
        min-width: 0;
        width: 100%;
    }

    .catalog-page tr.game-row:focus-within .game-title,
    .catalog-page tr.game-row:hover .game-title {
        background: transparent;
        box-shadow: none;
    }

    .catalog-page tr.game-row:focus-within {
        box-shadow: inset 3px 0 var(--accent-warm);
    }
}
