/* =============================================================================
   JOLKA (fill-in crossword) — game-specific styles
   Loaded together with games.css via $extraCss on the jolka page only.
   Uses the site design tokens from style.css :root. No inline styles are
   used by the game JS — the dynamic column count is carried by the
   data-cols attribute on .jolka-grid (widths 5–15 mapped below).
   ============================================================================= */

.jolka-layout {
    display: flex;
    align-items: flex-start;
    gap: 1.75rem;
    flex-wrap: wrap;
}

.jolka-main {
    flex: 0 1 auto;
    min-width: 0;
}

.jolka-side {
    flex: 1 1 240px;
    min-width: 220px;
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.25rem;
}

.jolka-side-title {
    font-size: 1rem;
    color: var(--color-gray-900);
    margin: 0 0 0.5rem;
}

.jolka-side-title + .jolka-clues + .jolka-side-title {
    margin-top: 1rem;
}

/* ---------------- Grid ---------------- */

.jolka-grid-wrap {
    max-width: 100%;
    overflow-x: auto;
}

.jolka-grid {
    /* cell size adapts to viewport so the widest grid still fits */
    --jk-cols: 13;
    --jk-cell: min(36px, calc((100vw - 2.5rem) / var(--jk-cols)));
    display: grid;
    gap: 2px;
    width: max-content;
    padding: 3px;
    background: var(--color-gray-800);
    border-radius: var(--border-radius-sm);
    touch-action: manipulation;
}

.jolka-grid[data-cols="5"]  { --jk-cols: 5;  grid-template-columns: repeat(5,  var(--jk-cell)); }
.jolka-grid[data-cols="6"]  { --jk-cols: 6;  grid-template-columns: repeat(6,  var(--jk-cell)); }
.jolka-grid[data-cols="7"]  { --jk-cols: 7;  grid-template-columns: repeat(7,  var(--jk-cell)); }
.jolka-grid[data-cols="8"]  { --jk-cols: 8;  grid-template-columns: repeat(8,  var(--jk-cell)); }
.jolka-grid[data-cols="9"]  { --jk-cols: 9;  grid-template-columns: repeat(9,  var(--jk-cell)); }
.jolka-grid[data-cols="10"] { --jk-cols: 10; grid-template-columns: repeat(10, var(--jk-cell)); }
.jolka-grid[data-cols="11"] { --jk-cols: 11; grid-template-columns: repeat(11, var(--jk-cell)); }
.jolka-grid[data-cols="12"] { --jk-cols: 12; grid-template-columns: repeat(12, var(--jk-cell)); }
.jolka-grid[data-cols="13"] { --jk-cols: 13; grid-template-columns: repeat(13, var(--jk-cell)); }
.jolka-grid[data-cols="14"] { --jk-cols: 14; grid-template-columns: repeat(14, var(--jk-cell)); }
.jolka-grid[data-cols="15"] { --jk-cols: 15; grid-template-columns: repeat(15, var(--jk-cell)); }

.jolka-cell {
    position: relative;
    width: var(--jk-cell);
    height: var(--jk-cell);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-white);
    border-radius: 2px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.jolka-cell:focus {
    outline: none;
}

.jolka-cell--block {
    background: var(--color-gray-800);
    cursor: default;
}

.jolka-cell-letter {
    font-weight: 700;
    font-family: var(--font-family);
    font-size: calc(var(--jk-cell) * 0.52);
    line-height: 1;
    color: var(--color-primary-dark);
    text-transform: uppercase;
}

/* crossword numbering (clue mode only) */
.jolka-cell-num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: calc(var(--jk-cell) * 0.26);
    font-weight: 600;
    color: var(--color-gray-500);
    line-height: 1;
}

/* selected word / selected cell */
.jolka-cell.is-slot {
    background: var(--color-gray-100);
    background: color-mix(in srgb, var(--color-primary) 8%, var(--color-white));
}

.jolka-cell.is-sel {
    background: var(--color-gray-200);
    background: color-mix(in srgb, var(--color-primary) 18%, var(--color-white));
    box-shadow: inset 0 0 0 2px var(--color-primary);
    z-index: 1;
}

/* starter letters + revealed hints — locked, sudoku-given style */
.jolka-cell.is-locked {
    background: var(--color-gray-100);
}

.jolka-cell.is-locked.is-slot {
    background: var(--color-gray-200);
}

.jolka-cell.is-locked .jolka-cell-letter {
    color: var(--color-gray-900);
}

/* "Check" marks */
.jolka-cell.is-wrong {
    background: var(--color-error-bg);
}

.jolka-cell.is-wrong .jolka-cell-letter {
    color: var(--color-error);
}

/* word-bank preview ghost letters */
.jolka-cell--ghost .jolka-cell-letter {
    color: var(--color-gray-400);
}

/* ---------------- Actions row ---------------- */

.jolka-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ---------------- Word bank ---------------- */

.jolka-bank-group {
    margin-bottom: 0.85rem;
}

.jolka-bank-len {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-gray-500);
    margin-bottom: 0.35rem;
}

.jolka-bank-words {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.jolka-bank-word {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.6rem;
    background: var(--color-gray-100);
    border-radius: var(--border-radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-gray-700);
    cursor: pointer;
    transition: var(--transition-fast);
}

.jolka-bank-word:hover {
    background: var(--color-gray-200);
}

.jolka-bank-word.is-preview {
    box-shadow: inset 0 0 0 2px var(--color-primary);
    background: var(--color-white);
}

.jolka-bank-word.is-done {
    text-decoration: line-through;
    color: var(--color-gray-400);
    background: transparent;
}

.jolka-bank-word.is-done:hover {
    background: var(--color-gray-100);
}

/* "wpisz" affordance — only visible while the word is previewed */
.jolka-bank-fill {
    display: none;
    border: none;
    background: var(--color-primary);
    color: var(--color-white);
    font-family: var(--font-family);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: lowercase;
    padding: 0.1rem 0.45rem;
    border-radius: var(--border-radius-full);
    cursor: pointer;
}

.jolka-bank-word.is-preview .jolka-bank-fill {
    display: inline-block;
}

.jolka-bank-fill:hover {
    background: var(--color-primary-dark);
}

.jolka-bank-help {
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--color-gray-500);
}

/* ---------------- Clue list (hand-made / licensed puzzles) ---------------- */

.jolka-clues {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0;
}

.jolka-clue {
    padding: 0.3rem 0.4rem;
    font-size: 0.9rem;
    color: var(--color-gray-600);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
}

.jolka-clue:hover {
    background: var(--color-gray-100);
}

.jolka-clue.is-active {
    background: var(--color-gray-100);
    background: color-mix(in srgb, var(--color-primary) 8%, var(--color-white));
    color: var(--color-gray-900);
}

.jolka-clue strong {
    color: var(--color-gray-900);
}

/* ---------------- On-screen keyboard ---------------- */

.jolka-kb {
    margin-top: 1.25rem;
    max-width: 520px;
    user-select: none;
    -webkit-user-select: none;
}

.jolka-kb-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 5px;
}

.jolka-key {
    flex: 1 1 0;
    max-width: 46px;
    min-width: 0;
    height: 44px;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius-sm);
    background: var(--color-gray-100);
    color: var(--color-gray-900);
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: var(--transition-fast);
    padding: 0;
    touch-action: manipulation;
}

.jolka-key:hover {
    background: var(--color-gray-200);
}

.jolka-key:active {
    background: var(--color-gray-300);
}

.jolka-key--wide {
    flex: 2 1 0;
    max-width: 96px;
}

/* ---------------- Responsive ---------------- */

@media (max-width: 900px) {
    .jolka-layout {
        flex-direction: column;
    }

    .jolka-side {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 600px) {
    .jolka-grid {
        --jk-cell: min(36px, calc((100vw - 1.75rem) / var(--jk-cols)));
    }

    .jolka-kb {
        max-width: 100%;
    }

    .jolka-key {
        height: 48px;
        font-size: 0.95rem;
    }
}
