/* Rummikub Solver: the tiles and the state tree. */

/* The four tile colors. Black is the site's own text color. */
.rk-red {
    --rk-color: #b91c1c;
}

.rk-blue {
    --rk-color: #1d4ed8;
}

.rk-black {
    --rk-color: var(--text);
}

.rk-orange {
    --rk-color: #d97706;
}

.rk-joker {
    --rk-color: var(--text-muted);
}

/* ---------- Tiles ---------- */

/* A tile in the result: its number in its color. One from the rack has a
   dark outline. */
.rk-tile {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2.5rem;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: var(--rk-color);
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.rk-tile.is-rack {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}

/* The table's sets, as many side by side as fit. */
.rk-sets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
}

/* A set's tiles, or the rack's. */
.rk-set {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* An emptied rack keeps a tile's height, so what is below it doesn't jump
   when the last tile leaves. */
.rk-sets,
.rk-set {
    min-height: 2.5rem;
}

/* Says so when the rack has been played out. */
.rk-set:empty::before {
    content: attr(data-empty-text);
    align-self: center;
    color: var(--text-muted);
}

/* A table whose tiles don't form sets: all of them in one wrapping line. */
.rk-set.is-loose {
    flex-basis: 100%;
}

/* ---------- Picker ---------- */

/* One color's thirteen tiles in rows of seven, so each stays wide enough to
   tap even in a card at its narrowest. */
.rk-picker {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0.25rem;
}

/* A picker tile is a button: the number over a line of marks, one per copy.
   An unused tile is drawn pale. */
.rk-pick {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    height: 2.75rem;
    padding: 0;
    color: color-mix(in srgb, var(--rk-color) 35%, var(--surface));
    background: var(--surface);
}

.rk-pick.is-used {
    color: var(--rk-color);
    background: var(--surface-muted);
}

/* Always as tall as a mark, so adding the first one doesn't move the
   number. */
.rk-marks {
    display: flex;
    gap: 0.1875rem;
    height: 0.375rem;
}

/* One dot per copy. */
.rk-mark {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: var(--primary);
}

/* ---------- State tree ---------- */

/* The tree's own palette: everything drawn in it except the labels, which
   stay in the site's muted text color. The greys are solid, so a crowd of
   paths stays the same shade as one. */
.rk-tree {
    --rk-dead: #e6e6e6;     /* a path that dies: grey at 90% lightness */
    --rk-live: #cccccc;     /* a path to a legal ending: grey at 80% */
    --rk-best: #000000;     /* the best move's path, and its ends */
    --rk-blocked: #991b1b;  /* a state with no legal next step */
}

/* script.js draws the tree to the width it finds here. */
.rk-tree svg {
    display: block;
    width: 100%;
}

.rk-tree text {
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    fill: var(--text-muted);
}

.rk-thread {
    fill: none;
    stroke: var(--rk-dead);
    stroke-width: calc(0.5px * var(--rk-weight, 1));
}

/* Every path that reaches a legal ending, as thin as the rest. The widths
   are for a crowded tree; script.js sets --rk-weight to 1.5 or 2 when the
   tree has more room, and sizes the dots to match. */
.rk-thread.is-live {
    stroke: var(--rk-live);
}

/* The path the best move took. */
.rk-thread.is-best {
    stroke: var(--rk-best);
    stroke-width: calc(1px * var(--rk-weight, 1));
    stroke-linecap: round;
}

.rk-node {
    fill: var(--rk-best);
}

.rk-node.is-blocked {
    fill: var(--rk-blocked);
}
