/*
 * QueenK Fixed Crossword Matrix
 * =============================
 *
 * The matrix is fixed.
 * The cell size is fixed for desktop.
 * The crossword generator only chooses which cells light up.
 */


.crossword-board.crossword-fixed-grid {
    --crossword-matrix-cell:
        34px;

    --crossword-matrix-gap:
        3px;


    display:
        grid !important;

    grid-template-columns:
        repeat(
            var(--crossword-fixed-columns),
            var(--crossword-matrix-cell)
        ) !important;

    grid-template-rows:
        repeat(
            var(--crossword-fixed-rows),
            var(--crossword-matrix-cell)
        ) !important;

    gap:
        var(--crossword-matrix-gap)
        !important;


    /*
     * Matrix dimensions now come from:
     *
     * 20 columns × fixed cell width
     * 12 rows    × fixed cell height
     *
     * No generated crossword can change this.
     */
    width:
        max-content !important;

    height:
        max-content !important;

    max-width:
        none !important;

    max-height:
        none !important;


    justify-content:
        center;

    align-content:
        center;

    justify-self:
        center;

    align-self:
        center;


    margin:
        0 auto !important;

    overflow:
        visible !important;

    transform:
        none !important;
}


/*
 * Unused physical matrix position.
 */
.crossword-board.crossword-fixed-grid
.crossword-grid-pixel {
    display:
        block;

    box-sizing:
        border-box;

    width:
        var(--crossword-matrix-cell);

    height:
        var(--crossword-matrix-cell);

    visibility:
        hidden;

    pointer-events:
        none;
}


/*
 * Active crossword position.
 */
.crossword-board.crossword-fixed-grid
.crossword-cell {
    box-sizing:
        border-box;

    width:
        var(--crossword-matrix-cell)
        !important;

    height:
        var(--crossword-matrix-cell)
        !important;

    min-width:
        var(--crossword-matrix-cell)
        !important;

    min-height:
        var(--crossword-matrix-cell)
        !important;

    max-width:
        var(--crossword-matrix-cell)
        !important;

    max-height:
        var(--crossword-matrix-cell)
        !important;

    aspect-ratio:
        1 / 1 !important;

    margin:
        0 !important;

    padding:
        0 !important;

    display:
        grid;

    place-items:
        center;

    border-width:
        2px !important;

    border-radius:
        7px !important;

    font-size:
        0.92rem !important;

    font-weight:
        700;

    line-height:
        1 !important;
}


/* Short laptop screens */
@media (
    min-width: 701px
) and (
    max-height: 760px
) {
    .crossword-board.crossword-fixed-grid {
        --crossword-matrix-cell:
            24px;

        --crossword-matrix-gap:
            2px;
    }
}


/* Mobile */
@media (
    max-width: 700px
) {
    .crossword-board.crossword-fixed-grid {
        --crossword-matrix-cell:
            18px;

        --crossword-matrix-gap:
            1px;
    }
}


/* =========================================================
   STUDY CROSSWORD — DESKTOP TERRITORY FIT
   =========================================================
   The fixed matrix remains 20 x 12.

   Only the physical cell size changes with available desktop
   space. This supersedes the old blanket 24px short-screen
   rule for Study Crossword only.
   ========================================================= */

@media (min-width: 981px) {

    body.queenk-study-crossword-active
    .crossword-board.crossword-fixed-grid {
        /*
         * At normal desktop widths this gives roughly 27-34px
         * cells instead of forcing every short screen to 24px.
         *
         * 20 columns + 19 gaps must fit the centre territory.
         */
        /*
         * Fit by BOTH width and height.
         *
         * Browser zoom reduces the effective CSS viewport,
         * so height must participate in sizing too.
         *
         * This keeps the complete 20 x 12 matrix inside its
         * Study territory instead of allowing a large desktop
         * width to force oversized cells on a shorter screen.
         */
        --crossword-matrix-cell:
            clamp(
                23px,
                min(
                    2.05vw,
                    4.2dvh
                ),
                31px
            ) !important;

        --crossword-matrix-gap:
            clamp(
                1px,
                min(
                    0.16vw,
                    0.30dvh
                ),
                2px
            ) !important;
    }
}


/* =========================================================
   STUDY CROSSWORD — VERY SHORT DESKTOP
   ---------------------------------------------------------
   Preserve the normal desktop composition. On a genuinely
   short CSS viewport (including browser zoom), permit a small
   additional matrix reduction rather than translating the
   crossword vertically.

   Word Wheel geometry is intentionally untouched.
   ========================================================= */

@media (
    min-width: 981px
) and (
    max-height: 620px
) {
    body.queenk-study-crossword-active
    .crossword-board.crossword-fixed-grid {
        --crossword-matrix-cell:
            clamp(
                21px,
                min(
                    2.05vw,
                    4.2dvh
                ),
                23px
            ) !important;
    }
}
