/* Sudoku: the GRID, and nothing else.
 *
 * Toolbar, statistics row, action bar, modal triggers, the four modals, the
 * settings rows and the win screen come from games-common.css now, the same
 * rules the other four games read. What is left is the 9x9 table with its thick
 * box borders, the contenteditable cell, the pencil-mark layout, the highlight
 * of the collinear cells and the pause overlay.
 */

.sk-difficulty-row {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-bottom: var(--s-3);
    min-width: 0;
}

.sk-difficulty-chips {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    gap: var(--s-2);
    /* One scrolling row, never two: the five levels wrapped on a phone and the
     * second row pushed the grid off the screen. Same trick the game switcher
     * uses, for the same reason. */
    width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
    scrollbar-width: thin;
}

.sk-difficulty-chip {
    flex: 0 0 auto;
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--c-line);
    border-radius: var(--r-pill);
    background: #fff;
    color: var(--c-ink-soft);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    min-height: 44px;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.sk-difficulty-chip:hover { border-color: var(--c-blue); color: var(--c-blue); }

.sk-difficulty-chip.is-active {
    background: var(--c-blue);
    border-color: var(--c-blue);
    color: #fff;
}

.sk-board-area {
    position: relative;
    display: flex;
    justify-content: center;
}

.sk-pause-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.96);
    border-radius: var(--r-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    z-index: 5;
    cursor: pointer;
}

.sk-pause-icon {
    font-size: 2rem;
    color: var(--c-blue);
}

.sk-pause-overlay p {
    margin: 0;
    font-weight: 700;
    color: var(--c-ink);
}

@keyframes shake {
    0%   { margin-left: 0; }
    25%  { margin-left: 0.1rem; }
    75%  { margin-left: -0.1rem; }
    100% { margin-left: 0; }
}

@keyframes sk-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    70%  { box-shadow: 0 0 0 12px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

table.sudoku {
    border-collapse: collapse;
    border: 2px solid #1f2937;
    margin: 0 auto;
    table-layout: fixed;
    max-width: 100%;
    background: #fff;
}

table.sudoku td {
    border: 1px solid #cbd5e1;
    width: var(--sk-cell, 44px);
    min-width: 0;
    max-width: var(--sk-cell, 44px);
    height: 44px;
    text-align: center;
    vertical-align: middle;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: background 0.1s ease;
}

table.sudoku td[data-given="1"] {
    background: #f1f5f9;
    color: #0f172a;
    cursor: default;
}

table.sudoku td:nth-child(3n) { border-right: 2px solid #1f2937; }

table.sudoku tr:nth-child(3n) td { border-bottom: 2px solid #1f2937; }

table.sudoku td.solvable { background: #fff; }

table.sudoku td.solvable .input {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    cursor: pointer;
    outline: none;
    line-height: 44px;
    text-align: center;
    overflow: hidden;
    color: #1d4ed8;
}

table.sudoku td.solvable .input:empty { min-height: 44px; }

table.sudoku td.solvable .input:focus { background: #dbeafe; }

table.sudoku td.solved { background: #ecfdf5; }

table.sudoku td.solved .input { color: #047857; }

table.sudoku td.wrong .input {
    animation: shake 0.1s ease-in-out 0s 4;
    color: #dc2626;
}

table.sudoku td.sk-error {
    background: #fee2e2 !important;
}

table.sudoku td.sk-error .input { color: #b91c1c; }

table.sudoku td.sk-hl-row,
table.sudoku td.sk-hl-col,
table.sudoku td.sk-hl-box {
    background: #f0f9ff;
}

table.sudoku td.sk-hl-num {
    background: #dbeafe;
}

table.sudoku td.sk-hl-active {
    background: #bfdbfe !important;
    outline: 2px solid #1d4ed8;
    outline-offset: -2px;
    z-index: 1;
}

.sk-pencil {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    line-height: 1;
}

.sk-pencil-cell {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.sk-pencil-mode table.sudoku td.solvable { cursor: crosshair; }

body.sk-pencil-mode #sk-btn-pencil { background: #fef3c7; color: #92400e; border-color: #fbbf24; }

table.sudoku.sudoku-won {
    box-shadow: 0 0 0 3px #15803d, 0 0 30px rgba(34, 197, 94, 0.3);
    transition: box-shadow 0.5s ease;
}

table.sudoku.sudoku-won td.solvable {
    animation: sk-pulse 0.8s ease-out;
}

/* The cell is fluid instead of switching at a breakpoint of its own (540px was
 * a registered legacy exception). Nine of them plus the borders have to fit the
 * height the frame leaves above the docked keypad, which is what
 * `--tools-board-max` carries, and the width of the screen. */
table.sudoku td {
    --sk-cell: clamp(24px, min(9.6vmin, calc(var(--tools-board-max, 420px) / 9.8)), 46px);
    width: var(--sk-cell);
    max-width: var(--sk-cell);
    height: var(--sk-cell);
    font-size: clamp(0.8rem, calc(var(--sk-cell) * 0.5), 1.3rem);
}

table.sudoku td.solvable .input {
    line-height: var(--sk-cell);
}

table.sudoku td.solvable .input:empty {
    min-height: var(--sk-cell);
}

.sk-pencil-cell {
    font-size: clamp(7px, calc(var(--sk-cell, 36px) * 0.24), 11px);
}

@media print {
    table.sudoku { border-color: #000 !important; }
    table.sudoku td { border-color: #999 !important; }
}
