/* Written methods for the Maths game. Class prefix wk-. Colours only from tokens.css. */

.wk-grid, .wk-bus {
  /* digits shrink for long numbers: 40px up to about 14 columns, then smaller */
  --fs: min(40px, calc(520px / var(--cols) / 0.9));
  --cw: calc(var(--fs) * 0.9);
}

.wk-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cw));
  font-family: var(--font-num);
  font-size: var(--fs);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ink);
  width: max-content;
}

.wk-c {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 1.25em;
  min-width: 0;
}

/* a carry digit that sits in its own cell, under the line */
.wk-c.wk-cy {
  align-items: flex-start;
  font-size: 0.5em;
  height: 2.5em;
  color: var(--ink-soft);
}

/* a carry digit written small inside a bus-stop digit cell */
.wk-c > .wk-cy {
  position: absolute;
  left: 0.05em;
  top: 0.08em;
  font-size: 0.45em;
  color: var(--ink-soft);
  line-height: 1;
}
.wk-has-cy { padding-left: 0.1em; }

/* the new digits of this step */
.wk-new {
  color: var(--rose-deep);
  background: color-mix(in srgb, var(--rose) 24%, transparent);
  border-radius: 0.18em;
  padding: 0 0.06em;
  box-shadow: 0 0 0 0.08em color-mix(in srgb, var(--rose) 24%, transparent);
}

.wk-place { color: var(--ink-soft); }

/* the multiplication line and the subtraction lines */
.wk-rule {
  grid-column: 1 / -1;
  border-top: 0.09em solid var(--ink);
  margin: 0.06em 0;
  border-radius: 0.05em;
}
.wk-ruleline { border-top: 0.07em solid var(--ink); height: 1.25em; align-items: flex-end; }
.wk-ruleline + .wk-ruleline { border-top: 0.07em solid var(--ink); }

/* the bus stop */
.wk-bus {
  display: inline-flex;
  align-items: flex-end;
  gap: 0.2em;
  font-family: var(--font-num);
  font-size: var(--fs);
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}
.wk-divisor {
  display: flex;
  align-items: center;
  height: 1.25em;
  padding-right: 0.1em;
}
.wk-bs {
  border-left: 0.1em solid var(--ink);
  border-top-left-radius: 0.5em 0.9em;
  padding-left: 0.1em;
  font-size: inherit;
}
.wk-bs:has(.wk-rem) { padding-right: 2.9em; }
.wk-bar, .wk-bar-gap { border-top: 0.1em solid var(--ink); }
.wk-rem {
  justify-content: flex-start;
  white-space: nowrap;
  overflow: visible;
  font-size: 0.7em;
  color: var(--orchid-deep);
  padding-left: 0.3em;
  z-index: 1;
}
.wk-rem .wk-new { white-space: nowrap; }

/* a big plain sum (table facts, x and / by 10, 100, 1000) */
.wk-sum {
  font-family: var(--font-num);
  font-size: var(--size-sum);
  font-weight: 800;
  color: var(--ink);
  line-height: 1.2;
  text-align: center;
}
.wk-ans { color: var(--orchid-deep); min-width: 1ch; display: inline-block; }

/* the lines that build up a fact */
.wk-lines {
  list-style: none;
  margin: 0.5rem auto 0;
  padding: 0;
  max-width: 560px;
  font-family: var(--font-num);
  font-size: var(--size-big);
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}
.wk-lines li { padding: 0.15em 0; }

/* place value chart and area grid */
.wk-pv, .wk-area {
  border-collapse: separate;
  border-spacing: 4px;
  margin: 0.5rem auto;
  font-family: var(--font-num);
  font-weight: 800;
  color: var(--ink);
}
.wk-pv { font-size: 30px; }
.wk-pv th {
  font-size: 0.55em;
  color: var(--ink-soft);
  padding: 0.1em 0.3em;
  white-space: nowrap;
}
.wk-pv .wk-pvl { text-align: right; font-size: 0.6em; color: var(--orchid-deep); padding-right: 0.5em; }
.wk-pv td {
  min-width: 1.5em;
  height: 1.5em;
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius-s);
}
.wk-pv td:empty { background: var(--lilac); border-style: dashed; border-color: var(--ink-soft); }

.wk-areawrap { display: flex; justify-content: center; margin-bottom: 0.75rem; }
.wk-area { font-size: 26px; }
.wk-area th { font-size: 0.8em; color: var(--ink-soft); padding: 0.1em 0.4em; }
.wk-area td {
  min-width: 2.6em;
  padding: 0.5em 0.4em;
  text-align: center;
  background: var(--blush);
  border: 3px solid var(--ink);
  border-radius: var(--radius-s);
}

/* the 1x to 9x list for long division */
.wk-multiples {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.9rem;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 0.15rem 1.4rem;
  justify-content: center;
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: var(--radius-m);
  width: max-content;
  max-width: 100%;
}
.wk-multiples li span { color: var(--ink-soft); }

/* lead: the multiples list sits under the layout and never spills out of a narrow hint card */
.wk-multiples {
  display: grid;
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
  grid-template-columns: repeat(3, minmax(0, auto));
  gap: 0.15rem 0.9rem;
  font-size: clamp(15px, 2.3vh, 20px);
  white-space: nowrap;
  clear: both;
}

/* lead: bus stop. The divisor sits beside the dividend row (row 2), and the bracket spans
   that row only, however many working rows follow. */
.wk-bus { align-items: flex-start; }
.wk-divisor { margin-top: 1.25em; }
.wk-bs { border-left: 0; border-top-left-radius: 0; }
.wk-bs .wk-c:not(.wk-bar) + .wk-bar { border-left: 0.1em solid var(--ink); border-top-left-radius: 0.5em 0.9em; }

/* ---- shared by the Year 6 tracks (lead, 1 Dec) ---- */
.wk-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; margin: 0 0.12em; font-family: var(--font-num); font-weight: 800; }
.wk-frac-n { padding: 0 0.2em 0.04em; border-bottom: 0.09em solid currentColor; }
.wk-frac-d { padding: 0.04em 0.2em 0; }
.wk-mixed { display: inline-flex; align-items: center; gap: 0.08em; vertical-align: middle; font-family: var(--font-num); font-weight: 800; }
.wk-say { font-family: var(--font); font-size: 20px; font-weight: 700; line-height: 1.35; color: var(--ink); }
.wk-big { font-family: var(--font-num); font-size: 40px; font-weight: 800; color: var(--ink); text-align: center; }
.wk-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.wk-chip { padding: 2px 12px; border: 3px solid var(--ink); border-radius: 999px; background: var(--paper); font-family: var(--font-num); font-size: 22px; font-weight: 800; }
.wk-chip.wk-on { background: var(--gold); }
.wk-chip.wk-off { opacity: 0.45; text-decoration: line-through; }

/* ==== DIV agent (1 Dec): long division up to 6 digits must fit a 400px hint card ====
   Width of a bus stop in em = columns x 0.9 + divisor and bracket (2.2) + room for "r 18" (2.9).
   The font size is the space available (--wk-avail, 340px by default, set it on a parent to change it)
   divided by that, never above 40px and never below 22px. The grid inside takes the same size. */
.wk-bus {
  --wk-avail: 340px;
  --fs: clamp(22px, calc(var(--wk-avail) / (var(--cols) * 0.9 + 2.2)), 40px);
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  box-sizing: border-box;
}
.wk-bus:has(.wk-rem) {
  --fs: clamp(22px, calc(var(--wk-avail) / (var(--cols) * 0.9 + 5.1)), 40px);
}
.wk-bus .wk-grid { --fs: inherit; }
.wk-bus .wk-grid, .wk-bus .wk-bs { max-width: none; }

/* the 1x to 9x list: two columns, so "9 × 99 = 891" never spills out of a narrow card */
.wk-multiples {
  grid-template-columns: repeat(2, minmax(0, auto));
  gap: 0.15rem 1.2rem;
  font-size: clamp(16px, 2.3vh, 20px);
  margin-left: auto;
  margin-right: auto;
}
