/*
 * All sizes are in em so the widget scales with the surrounding text.
 *
 * Nonogram widget. Everything is scoped under .hcp and resets the bits of
 * the host theme (table borders/padding, button styling, text colour) that
 * would otherwise leak in. The board carries its own light "paper" surface:
 * puzzle colours are arbitrary RGB from the database (some near black, some
 * pale), so a fixed neutral ground is the only way to keep every clue legible
 * whatever the surrounding theme (light, dark, terminal, ...).
 */
.hcp {
    --hcp-paper: #f3f1ec;
    --hcp-ink: #2b2b2b;
    --hcp-line: rgba(0, 0, 0, 0.14);
    color-scheme: light;
    box-sizing: border-box;
    width: fit-content;
    max-width: 100%;
    margin: 2em auto;
    padding: 1em;
    background: var(--hcp-paper);
    color: var(--hcp-ink);
    border-radius: 0.6em;
    box-shadow: 0 0.06em 0.2em rgba(0, 0, 0, 0.25);
    line-height: 1;
    font-variation-settings: normal;
    user-select: none;
    -webkit-user-select: none;
}

.hcp *,
.hcp *::before,
.hcp *::after {
    box-sizing: border-box;
}

/* ---- palette + controls ------------------------------------------------ */

.hcp-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    margin-bottom: 1em;
}

.hcp .palette {
    width: 2.5em;
    height: 2.5em;
    border-radius: 0.4em;
    border: 0.0625em solid var(--hcp-line);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.hcp .palette.selected {
    transform: scale(1.1);
    box-shadow: 0 0 0 0.2em var(--hcp-paper), 0 0 0 0.32em var(--hcp-ink);
}

/* the "eraser" swatch */
.hcp #color4 {
    background: repeating-conic-gradient(#bfbfbf 0% 25%, #fff 0% 50%) 50% / 1em 1em !important;
}

.hcp-actions {
    display: flex;
    gap: 0.5em;
    margin-left: 0.5em;
}

.hcp button {
    all: unset;
    box-sizing: border-box;
    padding: 0.5em 0.9em;
    font: inherit;
    font-size: 0.85em;
    color: var(--hcp-ink);
    background: #fff;
    border: 0.0625em solid var(--hcp-line);
    border-radius: 0.45em;
    cursor: pointer;
    white-space: nowrap;
}

.hcp button:hover {
    background: #e6e3dc;
}

.hcp button:focus-visible {
    outline: 0.12em solid var(--hcp-ink);
    outline-offset: 0.12em;
}

/* ---- grid -------------------------------------------------------------- */

.hcp-scroll {
    max-width: 100%;
    overflow-x: auto;
}

.hcp table.hcptable {
    margin: 0 auto;
    width: auto;
    table-layout: fixed;
    border: none;
    border-collapse: separate;
    border-spacing: 0.12em;
    background: transparent;
}

.hcp .hcptable tr,
.hcp .hcptable td {
    border: none;
    padding: 0;
    margin: 0;
    background: transparent;
}

.hcp .hcptable td {
    /* 1em = half a cell; shrinks so 14 columns fit on narrow screens */
    font-size: min(1em, calc((100vw - 4em) / 30));
    width: 2em;
    min-width: 2em;
    height: 2em;
    vertical-align: middle;
    text-align: center;
    font-weight: bold;
}

/* ---- clues ------------------------------------------------------------- */

.hcp .clue {
    display: inline-grid;
    place-items: center;
    font-size: 0.9em;
}

/* all cells of that colour form one block: ring it in the clue's colour */
.hcp .clue.joined {
    min-width: 1.6em;
    height: 1.6em;
    padding: 0 0.2em;
    border: 0.14em solid currentColor;
    border-radius: 999em;
    background: color-mix(in srgb, currentColor 12%, transparent);
}

/* playable cells (background-color set inline from the puzzle palette) */
.hcp .hcptable td.cell {
    border-radius: 0.3em;
    box-shadow: inset 0 0 0 0.0625em var(--hcp-line);
}

.hcp .hcptable td.cell.solved {
    animation: 1000ms ease-in-out 1 normal forwards hcp-pulse;
}

@keyframes hcp-pulse {
    to {
        border-radius: 0;
        box-shadow: none;
    }
}
