/* =============================================================================
   KAKURO — number crossword — game-specific styles
   Loaded together with games.css via $extraCss. Uses site design tokens.
   ============================================================================= */

/* Wrapper scrolls horizontally so a wide board never makes the page body
   scroll sideways. */
.kk-grid-wrap {
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 0.35rem;
}

.kk-grid {
    --kk-cell: 40px;
    display: grid;
    gap: 1px;
    width: -moz-max-content;
    width: max-content;
    background: var(--color-gray-400);
    border: 2px solid var(--color-gray-700);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 0;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.kk-grid[data-cols="6"] { --kk-cell: clamp(40px, 11vw, 58px); grid-template-columns: repeat(6, var(--kk-cell)); }
.kk-grid[data-cols="8"] { --kk-cell: clamp(36px, 9vw, 52px);  grid-template-columns: repeat(8, var(--kk-cell)); }
.kk-grid[data-cols="9"] { --kk-cell: clamp(34px, 8vw, 48px);  grid-template-columns: repeat(9, var(--kk-cell)); }

/* ---------------- Cells ---------------- */

.kk-cell {
    position: relative;
    width: var(--kk-cell);
    height: var(--kk-cell);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-family);
    font-weight: 700;
    font-size: calc(var(--kk-cell) * 0.5);
    line-height: 1;
    padding: 0;
    margin: 0;
}

/* Solid black block (no clues). */
.kk-block {
    background: var(--color-gray-800);
}

/* ---------------- Clue cells (split by a diagonal) ---------------- */

.kk-clue {
    background: var(--color-gray-800);
    color: var(--color-white);
    /* Diagonal line from top-left to bottom-right. */
    background-image: linear-gradient(
        to bottom right,
        transparent calc(50% - 1px),
        var(--color-gray-500) calc(50% - 1px),
        var(--color-gray-500) calc(50% + 1px),
        transparent calc(50% + 1px)
    );
}

.kk-clue-down,
.kk-clue-right {
    position: absolute;
    font-size: calc(var(--kk-cell) * 0.34);
    font-weight: 700;
    line-height: 1;
}

/* Vertical-run sum: lower-left triangle. */
.kk-clue-down {
    left: 8%;
    bottom: 6%;
}

/* Horizontal-run sum: upper-right triangle. */
.kk-clue-right {
    right: 8%;
    top: 6%;
}

/* ---------------- White (fillable) cells ---------------- */

.kk-white {
    background: var(--color-white);
    color: var(--color-gray-900);
    cursor: pointer;
    transition: var(--transition-fast);
}

.kk-white:hover {
    background: var(--color-gray-100);
}

.kk-white:focus-visible {
    outline: none;
}

/* Active-run highlight (row + column of the selected cell). */
.kk-white.is-run {
    background: var(--color-primary-light, var(--color-gray-100));
}

.kk-white.is-selected {
    background: var(--color-primary);
    color: var(--color-white);
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.kk-white.is-error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.kk-white.is-error.is-selected {
    background: var(--color-error);
    color: var(--color-white);
}

.kk-white.is-hint {
    color: var(--color-primary);
}

.kk-white.is-selected.is-hint {
    color: var(--color-white);
}

/* ---------------- On-screen keypad ---------------- */

.kk-keypad {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.75rem;
    max-width: 100%;
}

.kk-key {
    min-width: 2.4rem;
    padding: 0.55rem 0.6rem;
    border: 1px solid var(--color-gray-300);
    border-radius: var(--border-radius-sm);
    background: var(--color-white);
    color: var(--color-gray-900);
    font-family: var(--font-family);
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
    transition: var(--transition-fast);
}

.kk-key:hover {
    background: var(--color-gray-100);
}

.kk-key:active {
    background: var(--color-gray-200);
}

.kk-key--erase {
    min-width: 3.2rem;
    font-size: 1rem;
}

/* ---------------- Stats modal: best times ---------------- */

.kk-best-title {
    margin-top: 1rem;
    font-weight: 700;
    color: var(--color-gray-900);
}

.kk-best-list {
    list-style: none;
    margin: 0.35rem 0 0;
    padding: 0;
    font-size: 0.95rem;
    color: var(--color-gray-600);
}

.kk-best-list li {
    padding: 0.15rem 0;
}

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

@media (max-width: 600px) {
    .kk-grid[data-cols="6"] { --kk-cell: clamp(40px, calc((100vw - 2rem) / 6), 58px); }
    .kk-grid[data-cols="8"] { --kk-cell: clamp(34px, calc((100vw - 2rem) / 8), 52px); }
    .kk-grid[data-cols="9"] { --kk-cell: clamp(32px, calc((100vw - 2rem) / 9), 48px); }
}
