/* The game workspace has three jobs: choose, play, compare. */

.mobile-game-nav {
    display: none;
}

.game-workspace {
    display: grid;
    grid-template-columns:
        clamp(260px, 16vw, 280px)
        minmax(520px, 980px)
        minmax(300px, 340px);
    grid-template-areas: "controls board leaderboard";
    align-items: start;
    justify-content: center;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    gap: 20px;
}

#controls-wrapper {
    grid-area: controls;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

#controls-wrapper > *,
#controls-wrapper .puzzle-options,
#controls-wrapper .field-label,
#controls-wrapper select,
#controls-wrapper button {
    min-width: 0;
    max-width: 100%;
}

#controls-wrapper > *,
#controls-wrapper button,
#controls-wrapper select {
    width: 100%;
}

#game-area {
    grid-area: board;
    align-self: stretch;
    min-width: 0;
}

#current-leaderboard,
#current-leaderboard-panel {
    grid-area: leaderboard;
    position: sticky;
    top: 20px;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-height: calc(100dvh - 40px);
    overflow: hidden;
    border: 1px solid var(--divider-color);
    background: #ffffff;
}

.current-leaderboard-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 15px 16px 12px;
    gap: 12px;
    border-bottom: 1px solid var(--divider-color);
}

.current-leaderboard-header h2 {
    margin: 0;
    color: #17212b;
    font-size: 1rem;
    line-height: 1.2;
}

.current-leaderboard-header span,
.current-leaderboard-header p {
    color: #536272;
    font-size: 0.7rem;
    font-variant-numeric: tabular-nums;
}

#current-leaderboard-status {
    min-height: 42px;
    margin: 0;
    padding: 11px 16px;
    color: #536272;
    border-bottom: 1px solid var(--divider-color);
    background: #f5f7fa;
    font-size: 0.75rem;
    line-height: 1.35;
}

#current-leaderboard-status:empty {
    display: none;
}

#current-leaderboard-list {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
    scrollbar-gutter: stable;
}

.play-controls-panel {
    display: grid;
    padding: 12px;
    gap: 11px;
    border: 1px solid var(--divider-color);
    background: var(--menu-bg);
}

.play-controls-panel h2 {
    margin: 0;
    color: var(--menu-text);
    font-size: 0.9rem;
}

.control-hint-vertical {
    display: grid;
    justify-content: stretch;
    gap: 7px;
}

.control-hint-vertical > span {
    min-height: 28px;
}

.reset-board-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    gap: 8px;
    color: var(--menu-text);
    border-color: var(--divider-color);
    background: var(--menu-bg);
}

.reset-board-button svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.navigator-icon {
    width: 27px;
    height: 27px;
    flex: 0 0 auto;
    color: var(--navigator-focus);
    stroke: currentColor;
    stroke-width: 1.35;
    stroke-linecap: square;
    stroke-linejoin: miter;
}

.navigator-icon-focus {
    fill: color-mix(in srgb, var(--navigator-focus) 15%, transparent);
}

#current-leaderboard > .creator-panel,
#current-leaderboard-panel > .creator-panel {
    flex: 0 0 auto;
    margin: 0;
    border-width: 1px 0 0;
    background: var(--menu-bg);
}

#current-leaderboard > .creator-panel .game-actions,
#current-leaderboard-panel > .creator-panel .game-actions {
    grid-template-columns: 1fr;
}

#current-leaderboard-list .leaderboard-row {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr) auto;
    align-items: center;
    min-height: 46px;
    padding: 8px 14px;
    gap: 8px;
    border-bottom: 1px solid var(--divider-color);
    color: #17212b;
    background: #ffffff;
    font-size: 0.78rem;
}

#current-leaderboard-list .leaderboard-row:last-child {
    border-bottom: 0;
}

#current-leaderboard-list .leaderboard-rank {
    color: #5262b5;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

#current-leaderboard-list .leaderboard-username {
    min-width: 0;
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#current-leaderboard-list .leaderboard-row > strong {
    min-width: 0;
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#current-leaderboard-list .leaderboard-time {
    color: #2c3e50;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

#current-leaderboard-list .leaderboard-row > time {
    color: #2c3e50;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

#current-leaderboard-list .leaderboard-empty {
    margin: 0;
    padding: 18px 16px;
    color: #536272;
    font-size: 0.76rem;
    line-height: 1.45;
}

.size-preset-grid,
#grid-size-presets,
.size-presets {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.size-preset-grid button,
#grid-size-presets button,
.size-presets .size-preset {
    min-width: 0;
    min-height: 40px;
    padding: 6px;
    color: #2c3e50;
    border: 1px solid var(--divider-color);
    background: #ffffff;
    font-size: 0.75rem;
    font-weight: 750;
}

.size-preset-grid button[aria-pressed="true"],
#grid-size-presets button[aria-pressed="true"],
.size-presets .size-preset[aria-pressed="true"] {
    color: #ffffff;
    border-color: #2c3e50;
    background: #2c3e50;
}

.puzzle-action-list,
#puzzle-actions,
.game-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
}

.board-frame {
    max-width: 100%;
    overflow: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable both-edges;
}

.board-frame #grid-wrapper {
    flex: 0 0 auto;
    min-width: min-content;
    margin: auto;
}

/* Native semantics with an Infer-owned square control surface. */
select {
    min-height: 44px;
    box-sizing: border-box;
    appearance: none;
    padding: 0 30px 0 12px;
    color: var(--menu-text);
    border: 2px solid var(--divider-color);
    background-color: var(--menu-bg);
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

select:hover {
    border-color: var(--menu-text);
    background-color: var(--hud-bg);
}

select:focus-visible {
    border-color: var(--navigator-focus);
    outline: 3px solid var(--button-focus-ring);
    outline-offset: 2px;
}

label:has(> select) {
    position: relative;
}

label:has(> select)::after {
    position: absolute;
    right: 11px;
    bottom: 18px;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--menu-text);
    border-bottom: 2px solid var(--menu-text);
    content: "";
    pointer-events: none;
    transform: rotate(45deg);
}

#grid-size-select {
    padding: 0 28px 0 8px;
    border-left: 5px solid var(--cell-fill);
}

#difficulty-slider {
    padding: 0 28px 0 8px;
}

#difficulty-slider:has(option[value="0"]:checked) {
    border-left: 5px solid var(--state-success);
}

#difficulty-slider:has(option[value="1"]:checked) {
    border-left: 5px solid var(--state-info);
}

#difficulty-slider:has(option[value="2"]:checked) {
    border-left: 5px solid var(--cell-border-thick);
}

#difficulty-slider:has(option[value="3"]:checked) {
    border-left: 5px solid var(--state-error);
}

@media (min-width: 1280px) and (min-height: 600px) {
    .game-stage {
        align-self: stretch;
        min-height: 0;
    }

    .board-frame {
        flex: 1 1 auto;
        min-height: max(520px, calc(100dvh - 232px));
    }
}

@media (min-width: 761px) and (max-width: 1279px) {
    .game-workspace {
        grid-template-columns: minmax(260px, 280px) minmax(0, 1fr);
        grid-template-areas:
            "controls board"
            "leaderboard board";
    }

    #current-leaderboard,
    #current-leaderboard-panel {
        position: static;
        max-height: 360px;
    }
}

@media (max-width: 760px), (max-width: 900px) and (max-height: 500px) {
    html,
    body,
    #app,
    #content-wrapper {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        overflow-x: clip;
    }

    #content-wrapper {
        min-height: 100svh;
        min-height: 100dvh;
    }

    .game-workspace {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "mobile-view";
        align-items: start;
        flex: 1 1 auto;
        min-width: 0;
        min-height: 0;
        max-width: 100%;
        gap: 14px;
    }

    .mobile-game-nav {
        position: sticky;
        top: max(8px, env(safe-area-inset-top));
        z-index: 90;
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        border: 1px solid var(--divider-color);
        background: var(--menu-bg);
    }

    .mobile-game-nav [role="tablist"] {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 1px;
        background: var(--divider-color);
    }

    .mobile-view-tab {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        min-height: 52px;
        padding: 7px 8px;
        gap: 7px;
        color: var(--secondary-text);
        border: 0;
        background: var(--menu-bg);
        font-size: 0.78rem;
        font-weight: 750;
        line-height: 1;
        touch-action: manipulation;
    }

    .mobile-view-tab svg {
        width: 19px;
        height: 19px;
        flex: 0 0 auto;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: square;
        stroke-linejoin: miter;
    }

    .mobile-view-tab[aria-selected="true"] {
        color: var(--button-text);
        background: var(--button-bg);
    }

    .mobile-view-tab:active {
        background: var(--surface-3);
    }

    .mobile-view-tab[aria-selected="true"]:active {
        background: var(--button-active-bg);
    }

    .game-workspace > #controls-wrapper,
    .game-workspace > #game-area,
    .game-workspace > #current-leaderboard,
    .game-workspace > #current-leaderboard-panel {
        grid-area: mobile-view;
        display: none !important;
    }

    .game-workspace[data-mobile-view="controls"] > #controls-wrapper,
    .game-workspace[data-mobile-view="puzzle"] > #game-area,
    .game-workspace[data-mobile-view="times"] > #current-leaderboard,
    .game-workspace[data-mobile-view="times"] > #current-leaderboard-panel {
        display: flex !important;
    }

    .game-workspace[data-mobile-view="puzzle"] > #game-area {
        align-self: start;
        justify-content: flex-start;
        min-height: 0;
    }

    #controls-wrapper,
    #game-area,
    #current-leaderboard,
    #current-leaderboard-panel {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    #current-leaderboard,
    #current-leaderboard-panel {
        max-height: none;
    }

    #current-leaderboard-list {
        max-height: 320px;
    }

    .board-frame {
        justify-content: flex-start;
        flex: 0 1 auto;
        width: 100%;
        min-width: 0;
        min-height: 0;
        max-width: 100%;
        overflow: clip;
    }

    .board-frame #grid-wrapper {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        margin-inline: auto;
    }

    .site-footer {
        margin-top: auto;
        min-width: 0;
        max-width: 100%;
    }
}

@media (max-width: 390px) {
    .mobile-view-tab {
        flex-direction: column;
        min-height: 58px;
        gap: 4px;
        font-size: 0.7rem;
    }
}

@media (max-width: 420px) {
    .size-preset-grid,
    #grid-size-presets,
    .size-presets {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #current-leaderboard-list .leaderboard-row {
        grid-template-columns: 1.75rem minmax(0, 1fr) auto;
        padding-inline: 10px;
        gap: 6px;
    }
}
