/* Balls into Boxes Calculator (/balls-into-boxes): the clickable table of the twelvefold way, the formula as a row of
   terms, the long exact value, and the distributions drawn as boxes with balls. Tiles, panels and buttons come from
   the app kit (css/app-kit, docs/app-kit.md). Loaded only on this app's page (StylePaths). */

.bb-landing-app .bb-panel { display: flex; flex-direction: column; gap: var(--ak-space-2, 0.6rem); }
.bb-landing-app .bb-note { margin: 0; }

/* The twelvefold way: a row label and three cells per row, a column head over each cell. */
.bb-landing-app .bb-grid {
    display: grid;
    grid-template-columns: minmax(7rem, 1.15fr) repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    align-items: stretch;
}
.bb-landing-app .bb-col {
    align-self: end;
    padding: 0 0.2rem;
    color: var(--ak-muted);
    font-size: var(--ak-fs-xs, 0.75rem);
    font-weight: 600;
    text-align: center;
}
.bb-landing-app .bb-row {
    display: flex;
    align-items: center;
    color: var(--ak-text);
    font-size: var(--ak-fs-sm, 0.85rem);
    font-weight: 600;
    line-height: 1.25;
}
.bb-landing-app .bb-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
    min-width: 0;
    min-height: 3.6rem;
    padding: 0.35rem 0.3rem;
    border: 1px solid var(--ak-border);
    border-radius: var(--ak-radius-sm, 6px);
    background: var(--ak-field);
    color: var(--ak-text);
    font: inherit;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}
.bb-landing-app .bb-cell:hover { background: var(--ak-hover); }
.bb-landing-app .bb-cell:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ak-accent); }
.bb-landing-app .bb-cell.is-selected {
    border: 2px solid var(--ak-accent);
    background: color-mix(in srgb, var(--ak-accent) 14%, var(--ak-field));
}
.bb-landing-app .bb-cell-value {
    max-width: 100%;
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
    overflow-wrap: anywhere;
}
.bb-landing-app .bb-cell.is-zero .bb-cell-value { color: var(--ak-muted); font-weight: 600; }
.bb-landing-app .bb-cell-hint { max-width: 100%; color: var(--ak-muted); font-size: var(--ak-fs-xs, 0.72rem); line-height: 1.2; overflow-wrap: anywhere; }

@media (max-width: 640px) {
    .bb-landing-app .bb-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .bb-landing-app .bb-corner { display: none; }
    .bb-landing-app .bb-row { grid-column: 1 / -1; margin-top: 0.25rem; font-size: var(--ak-fs-xs, 0.78rem); }
    .bb-landing-app .bb-cell-value { font-size: 0.9rem; }
}

/* The formula: terms joined by "=", wrapping between terms. */
.bb-landing-app .bb-formula-head { display: flex; align-items: center; justify-content: space-between; gap: var(--ak-space-2, 0.5rem); }
.bb-landing-app .bb-symbolic { margin: 0; color: var(--ak-muted); font-size: var(--ak-fs-sm, 0.88rem); font-style: italic; }
.bb-landing-app .bb-formula {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.2rem 0.45rem;
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.5;
}
.bb-landing-app .bb-term { white-space: nowrap; }
.bb-landing-app .bb-term--name { font-weight: 700; color: var(--ak-accent); }
.bb-landing-app .bb-term:last-child { font-weight: 700; }
.bb-landing-app .bb-eq { color: var(--ak-muted); }
.bb-landing-app .bb-why { margin: 0; padding-top: 0.5rem; border-top: 1px solid var(--ak-grid); line-height: 1.5; }
.bb-landing-app .bb-why:empty { display: none; }

.bb-landing-app .bb-exact { display: flex; flex-direction: column; gap: 0.35rem; }
.bb-landing-app .bb-exact-digits {
    margin: 0;
    max-height: 12rem;
    overflow-y: auto;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--ak-border);
    border-radius: var(--ak-radius-sm, 6px);
    background: var(--ak-field);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: var(--ak-fs-sm, 0.88rem);
    line-height: 1.6;
    overflow-wrap: anywhere;
    word-break: break-all;
}
.bb-landing-app .bb-exact-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.4rem; }

/* The distributions: a numbered card per way, its boxes side by side. */
.bb-landing-app .bb-subtitle { margin: 0; font-weight: 600; }
.bb-landing-app .bb-draw-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.4rem; }
.bb-landing-app .bb-draw-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.bb-landing-app .bb-draw-list {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.45rem;
    max-height: 26rem;
    margin: 0;
    padding: 0 0.2rem 0.2rem 0;
    overflow-y: auto;
    list-style: none;
}
.bb-landing-app .bb-draw-list:empty { display: none; }
.bb-landing-app .bb-dist {
    display: flex;
    align-items: flex-end;
    gap: 0.35rem;
    padding: 0.3rem 0.45rem 0.35rem;
    border: 1px solid var(--ak-grid);
    border-radius: var(--ak-radius-sm, 6px);
    background: var(--ak-panel);
}
.bb-landing-app .bb-dist-n { align-self: flex-start; min-width: 1.4rem; color: var(--ak-muted); font-size: 0.68rem; font-variant-numeric: tabular-nums; }
.bb-landing-app .bb-boxes { display: flex; align-items: flex-end; gap: 0.25rem; direction: ltr; }
.bb-landing-app .bb-nothing { color: var(--ak-muted); font-weight: 700; }
.bb-landing-app .bb-box { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; }
.bb-landing-app .bb-box-balls {
    display: flex;
    flex-wrap: wrap-reverse;
    align-content: flex-start;
    justify-content: center;
    gap: 2px;
    min-width: 1.5rem;
    max-width: 4.6rem;
    min-height: 1.5rem;
    padding: 3px;
    border: 2px solid var(--ak-text);
    border-top: none;
    border-radius: 0 0 5px 5px;
}
.bb-landing-app .bb-dist--same .bb-box-balls { border-color: var(--ak-muted); border-style: dashed; border-top: none; }
.bb-landing-app .bb-box.is-empty .bb-box-balls { opacity: 0.55; }
.bb-landing-app .bb-box-label { order: 2; color: var(--ak-muted); font-size: 0.62rem; font-weight: 700; line-height: 1; }
.bb-landing-app .bb-ball {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.05rem;
    height: 1.05rem;
    border-radius: 50%;
    background: var(--bb-ball, var(--ak-accent));
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.55);
}
.bb-landing-app .bb-ball--same { background: var(--ak-accent); }

.bb-landing-app .bb-nk { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.bb-landing-app [data-ak-field="rule"] > .ak-seg-btn { padding-inline: 0.35rem; white-space: normal; line-height: 1.15; text-align: center; }
