.game-v3-card[data-home-screen="sorter"] {
    --v3-accent: #138b9a;
    --v3-soft: #dcf8f4;
}

.sorter-game-shell {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 10px;
    color: #13243b;
}

.sorter-game-topbar,
.sorter-game-hud,
.sorter-game-controls {
    display: flex;
    align-items: center;
}

.sorter-game-topbar {
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.sorter-game-title {
    min-width: 0;
}

.sorter-game-title small {
    display: block;
    color: #188595;
    font-size: 10px;
    font-weight: 950;
    letter-spacing: .08em;
}

.sorter-game-title h3 {
    margin: 1px 0 0;
    font-size: 21px;
    line-height: 1.2;
}

.sorter-icon-button {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid #d6e0e8;
    border-radius: 50%;
    background: #fff;
    color: #263951;
    font-size: 18px;
    font-weight: 900;
    box-shadow: 0 3px 0 #dce4e9;
    cursor: pointer;
}

.sorter-game-hud {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
}

.sorter-difficulty {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 8px;
    padding: 4px;
    border: 1px solid rgba(21, 112, 130, .18);
    border-radius: 8px;
    background: rgba(224, 243, 246, .72);
}

.sorter-difficulty button {
    min-height: 45px;
    padding: 5px 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #526377;
    cursor: pointer;
}

.sorter-difficulty b,
.sorter-difficulty small { display: block; }
.sorter-difficulty b { font-size: 12px; }
.sorter-difficulty small { margin-top: 1px; font-size: 9px; font-weight: 800; }
.sorter-difficulty button.active { border-color: #168e98; background: #fff; color: #126873; box-shadow: 0 3px 8px rgba(19, 93, 105, .13); }
.sorter-difficulty button:disabled { cursor: default; opacity: .66; }
.sorter-difficulty button.active:disabled { opacity: 1; }

.sorter-game-stat {
    min-width: 0;
    padding: 7px 5px;
    border: 1px solid rgba(21, 112, 130, .18);
    border-radius: 7px;
    background: rgba(255, 255, 255, .94);
    text-align: center;
    box-shadow: 0 3px 0 rgba(35, 83, 98, .09);
}

.sorter-game-stat span {
    display: block;
    color: #718094;
    font-size: 9px;
    font-weight: 900;
}

.sorter-game-stat strong {
    display: block;
    overflow: hidden;
    color: #15334d;
    font-size: 19px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sorter-stage-wrap {
    position: relative;
    overflow: hidden;
    border: 3px solid #1a3955;
    border-radius: 8px;
    background: #0d6f9f;
    box-shadow: 0 7px 0 #102a40, 0 12px 24px rgba(14, 54, 80, .2);
}

#sorterCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 6 / 7;
    touch-action: none;
}

.sorter-game-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(5, 24, 45, .64);
    backdrop-filter: blur(3px);
}

.sorter-game-overlay[hidden],
.sorter-game-overlay.is-hidden {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.sorter-game-dialog {
    width: min(100%, 330px);
    padding: 20px;
    border: 2px solid rgba(255, 255, 255, .84);
    border-radius: 8px;
    background: #fff;
    text-align: center;
    box-shadow: 0 10px 0 rgba(6, 33, 57, .24);
}

.sorter-game-dialog b {
    color: #138b9a;
    font-size: 11px;
    letter-spacing: .08em;
}

.sorter-game-dialog strong {
    display: block;
    margin: 4px 0;
    color: #13243b;
    font-size: 42px;
}

.sorter-game-dialog p {
    margin: 0 0 14px;
    color: #5e7085;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.5;
}

.sorter-game-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 10px;
}

.sorter-lane-button {
    position: relative;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    align-items: center;
    min-height: 60px;
    padding: 6px;
    border: 2px solid var(--lane-color);
    border-radius: 7px;
    background: color-mix(in srgb, var(--lane-color) 11%, #fff);
    color: #172a41;
    text-align: left;
    box-shadow: 0 4px 0 color-mix(in srgb, var(--lane-color) 28%, #cad5dc);
    cursor: pointer;
    touch-action: manipulation;
}

.sorter-lane-button:nth-child(1) { --lane-color: #e5695f; }
.sorter-lane-button:nth-child(2) { --lane-color: #19a8a4; }
.sorter-lane-button:nth-child(3) { --lane-color: #526bd7; }

.sorter-lane-button:active,
.sorter-lane-button.is-pressed {
    transform: translateY(3px);
    box-shadow: 0 1px 0 color-mix(in srgb, var(--lane-color) 28%, #cad5dc);
}

.sorter-lane-button img {
    width: 38px;
    height: 46px;
    object-fit: contain;
}

.sorter-lane-button span {
    min-width: 0;
}

.sorter-lane-button b,
.sorter-lane-button small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sorter-lane-button b {
    font-size: 12px;
}

.sorter-lane-button small {
    margin-top: 2px;
    color: #6a788a;
    font-size: 9px;
    font-weight: 800;
}

.sorter-game-help {
    margin: 8px 0 0;
    color: #627187;
    font-size: 11px;
    font-weight: 800;
    text-align: center;
}

.sorter-primary-button {
    width: 100%;
    min-height: 48px;
    margin-top: 8px;
    border: 0;
    border-radius: 7px;
    background: linear-gradient(135deg, #12a8a4, #1766c1);
    color: #fff;
    font-size: 15px;
    font-weight: 950;
    box-shadow: 0 5px 0 #12477c;
    cursor: pointer;
}

.sorter-start-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 150px;
    align-items: center;
    gap: 12px;
    margin-top: 9px;
    padding: 11px;
    border: 1px solid rgba(21, 112, 130, .18);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 7px 18px rgba(20, 69, 83, .12);
}
.sorter-start-panel .sorter-difficulty { margin: 0 0 7px; }
.sorter-start-panel > div > strong { display: block; font-size: 15px; }
.sorter-start-panel > div > p { margin: 2px 0 0; color: #627187; font-size: 10px; font-weight: 800; }
.sorter-start-panel .sorter-primary-button { min-height: 56px; margin: 0; }

@media (max-width: 760px) {
    .sorter-game-shell {
        padding: 7px 7px calc(16px + env(safe-area-inset-bottom));
    }

    .sorter-game-topbar {
        margin-bottom: 5px;
    }

    .sorter-game-title h3 {
        font-size: 18px;
    }

    .sorter-game-hud {
        margin-bottom: 6px;
    }

    .sorter-difficulty { margin-bottom: 6px; }
    .sorter-difficulty button { min-height: 40px; }

    .sorter-game-stat {
        padding: 5px 3px;
    }

    .sorter-game-stat strong {
        font-size: 16px;
    }

    .sorter-game-controls {
        margin-top: 7px;
    }

    .sorter-lane-button {
        grid-template-columns: 32px minmax(0, 1fr);
        min-height: 54px;
        padding: 4px;
    }

    .sorter-lane-button img {
        width: 30px;
        height: 40px;
    }

    .sorter-lane-button b {
        font-size: 10px;
    }

    .sorter-lane-button small {
        display: none;
    }

    .sorter-game-help {
        margin-top: 6px;
        font-size: 10px;
    }

    .sorter-primary-button {
        min-height: 44px;
        margin-top: 6px;
    }

    .sorter-start-panel {
        position: sticky;
        z-index: 22;
        bottom: calc(8px + env(safe-area-inset-bottom));
        grid-template-columns: minmax(0, 1fr) 112px;
        gap: 7px;
        margin-top: 7px;
        padding: 8px;
    }
    html[data-ui-version="new"] .sorter-start-panel { bottom: calc(76px + env(safe-area-inset-bottom)); }
    .sorter-start-panel .sorter-difficulty button { min-height: 38px; padding: 4px; }
    .sorter-start-panel > div > strong { font-size: 13px; }
    .sorter-start-panel > div > p { overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
    .sorter-start-panel .sorter-primary-button { min-height: 50px; margin: 0; }
}
