:root {
  --bg: #f8f4ef;
  --panel: #ffffff;
  --text: #2f251f;
  --muted: #6f6258;
  --line: #ddcec0;
  --brand: #c30000;
  --brand-soft: #f9dddd;
  --accent: #7a6f60;
  --success: #2f7d4f;
  --success-soft: #e3f3e8;
  --danger: #b33632;
  --blue: #1d63d6;
  --blue-soft: #e4edfb;
  --carry: #7b3fa0;
  --carry-soft: #f1e8f7;
  --hl: #fff1b8;
  --cell: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #fff8f3, var(--bg) 50%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, p {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fcf8f3);
  box-shadow: 0 4px 20px rgba(90, 52, 38, 0.08);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.master-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.topbar h1 {
  font-size: 1.3rem;
  color: var(--brand);
}

.topbar p {
  color: var(--muted);
  margin-top: 2px;
  font-size: 0.85rem;
}

/* ---------- Level picker ---------- */

.level-title {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.level-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 4px;
  min-height: 44px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.15;
  text-align: center;
}

.level-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 20px;
}

.board-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 12px;
  box-shadow: 0 6px 18px rgba(90, 52, 38, 0.06);
}

/* The board's digit size is picked in script.js (fitBoard) to fill this area. */
.board-area {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(90, 52, 38, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- The problem board ---------- */

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--cell));
  justify-content: center;
  row-gap: var(--row-gap, 4px);
}

.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: calc(var(--cell) * 0.62);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  position: relative;
}

.cell.sign {
  color: var(--muted);
}

.cell.factor {
  border-radius: 10px;
  transition: background 0.2s ease;
}

.cell.factor.hl {
  background: var(--hl);
  box-shadow: inset 0 0 0 2px #e6c84f;
}

.cell.factor.hl-bottom {
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 2px var(--blue);
}

/* answer boxes */
.ans-box {
  width: calc(var(--cell) - 6px);
  height: calc(var(--cell) - 6px);
  border: 2px dashed var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: #fffdfa;
}

.ans-box.filled {
  border: 2px solid transparent;
  background: transparent;
}

.ans-box.placeholder-zero {
  color: var(--muted);
}

.ans-box.active {
  border: 3px solid var(--blue);
  background: var(--blue-soft);
  animation: pulse 1.4s ease-in-out infinite;
}

.ans-box.wrong {
  border-color: var(--danger) !important;
  background: #fbe9e8 !important;
  color: var(--danger);
  animation: shake 0.35s ease;
}

.ans-box.hl-col {
  background: var(--hl);
}

/* regroup (carry) boxes */
.cell.carry-cell {
  height: calc(var(--cell) * 0.72);
  align-items: flex-end;
}

.carry-box {
  width: calc(var(--cell) * 0.62);
  height: calc(var(--cell) * 0.62);
  border: 2px solid var(--carry);
  border-radius: 8px;
  background: var(--carry-soft);
  color: var(--carry);
  font-size: calc(var(--cell) * 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pop-in 0.35s ease;
}

.carry-box.active {
  border-width: 3px;
  animation: pop-in 0.35s ease, pulse 1.4s ease-in-out 0.35s infinite;
}

.carry-box.wrong {
  border-color: var(--danger);
  background: #fbe9e8;
  color: var(--danger);
  animation: shake 0.35s ease;
}

.carry-box.in-use {
  box-shadow: 0 0 0 3px var(--hl), 0 0 0 5px #e6c84f;
}

.carry-box.done {
  opacity: 0.35;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  animation: none;
}

.rule {
  grid-column: 1 / -1;
  height: 0;
  border-top: 3px solid var(--text);
  margin: 4px 0;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29, 99, 214, 0.35); }
  50% { box-shadow: 0 0 0 6px rgba(29, 99, 214, 0); }
}

@keyframes pop-in {
  0% { transform: scale(0.2); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.think-line {
  min-height: 2.8em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  max-width: 34ch;
  line-height: 1.4;
}

.think-line .tag {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  margin-right: 6px;
  vertical-align: 2px;
  background: var(--blue);
  color: #fff;
}

.think-line .tag.regroup {
  background: var(--carry);
}

.think-line .tag.add {
  background: var(--success);
}

.feedback {
  min-height: 2.6rem;
  font-weight: 700;
  text-align: center;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 1.05rem;
  line-height: 1.5;
  width: 100%;
  max-width: 440px;
}

.feedback.correct {
  color: var(--success);
  background: var(--success-soft);
  animation: feedback-pop 0.5s ease;
}

.feedback.incorrect {
  color: var(--danger);
  background: #fbe9e8;
}

@keyframes feedback-pop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------- Keypad ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.key-btn {
  min-height: 54px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fffdfa;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  box-shadow: 0 3px 0 var(--line);
  touch-action: manipulation;
}

.key-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--line);
}

.keypad.locked .key-btn {
  opacity: 0.4;
  pointer-events: none;
}

.practice-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.primary {
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  min-height: 52px;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  background: var(--brand);
  width: 100%;
}

.primary.success {
  background: var(--success);
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.9rem;
  padding: 6px;
}

.score-line {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.skal-tip {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.skal-tip strong {
  color: var(--brand);
}

.site-footer {
  text-align: center;
  padding: 6px 20px 10px;
  color: var(--muted);
  font-size: 0.75rem;
}

.site-footer a {
  color: var(--brand);
}

/* Big enough screens (laptops, tablets, smart boards): everything fits on one
   screen. The board fills the left side; the panel scrolls on its own only if
   it ever runs out of room. */
@media (min-width: 760px) and (min-height: 560px) {
  body {
    height: 100vh;
    height: 100dvh;
  }
  .layout {
    flex: 1;
    min-height: 0;
    /* The panel narrows on upright tablets so the board keeps more room. */
    grid-template-columns: minmax(0, 1fr) clamp(280px, 30vw, 360px);
    grid-template-rows: minmax(0, 1fr);
  }
  .board-panel {
    min-height: 0;
  }
  .board-area {
    flex: 1;
    min-height: 0;
  }
  .side-panel {
    min-height: 0;
    overflow-y: auto;
  }
}

/* Phones (and very short screens): the board is stacked above the panel, so
   keep the number pad right under the tabs where thumbs (and eyes) are, and
   don't hold empty space for a hint that isn't showing. */
@media (max-width: 759px), (max-height: 559px) {
  #practiceKeypadSlot,
  #teachKeypadSlot {
    order: -1;
  }
  .think-line {
    font-size: 1.05rem;
    line-height: 1.35;
  }
  .feedback:not(:empty) {
    font-size: 0.95rem;
  }
}

@media (max-width: 600px) {
  .topbar {
    padding: 8px 16px;
  }
  .topbar p {
    display: none;
  }
  .layout {
    padding: 12px 16px 16px;
    gap: 12px;
  }
  .key-btn {
    min-height: 48px;
  }
}

/* ---------- Teach Me ---------- */

.mute-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mute-btn:hover {
  border-color: var(--brand);
}

.mode-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.mode-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 12px;
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}

.mode-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.teach-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.teach-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: var(--line);
  padding: 0;
}

.teach-dot.active {
  background: var(--brand);
  transform: scale(1.25);
}

.teach-dot.done {
  background: var(--success);
}

.teach-caption {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
}

.teach-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.speak-btn {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
  min-height: 52px;
  border-radius: 999px;
  font-weight: 600;
}

.speak-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
  min-height: 52px;
  border-radius: 999px;
  font-weight: 700;
}

.ghost:disabled {
  opacity: 0.35;
  cursor: default;
}

.demo-math {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 999px;
  background: var(--hl);
  font-size: 1.15rem;
  line-height: 1.3;
  font-weight: 800;
  animation: feedback-pop 0.5s ease;
}

/* ---------- Partial products: line labels ("40 × 7") ---------- */

.board.has-labels {
  grid-template-columns: repeat(var(--cols, 4), var(--cell)) calc(var(--cell) * var(--label-units, 0));
}

.cell.line-label {
  justify-content: flex-start;
  padding-left: calc(var(--cell) * 0.3);
  font-size: calc(var(--cell) * 0.36);
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.cell.line-label.current {
  color: var(--blue);
  font-weight: 800;
}

/* ---------- Strategy buttons (like the Rounding Lab's section toggle) ---------- */

.strategy-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  width: calc(100% - 40px);
  max-width: 1240px;
  margin: 12px auto 0;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 4px 12px rgba(90, 52, 38, 0.06);
}

.strategy-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 8px 16px;
  min-height: 40px;
  border-radius: 999px;
  white-space: nowrap;
}

.strategy-btn.active {
  background: var(--brand);
  color: #fff;
}

@media (max-width: 600px) {
  .strategy-row {
    width: calc(100% - 32px);
    margin-top: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
  }
  .strategy-btn {
    padding: 6px 12px;
    min-height: 36px;
    font-size: 0.9rem;
  }
}

/* The step line and a hint / "You did it!" share one fixed-height spot: the
   hint takes the step line's place, so the board never shrinks or jumps. */
.board-panel:has(.feedback:not(:empty)) .think-line {
  display: none;
}

.feedback:empty {
  display: none;
}

.think-line,
.feedback:not(:empty) {
  height: 4rem;
  min-height: 0;
  flex-shrink: 0;
}

.feedback:not(:empty) {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.3;
  padding: 4px 12px;
}

/* Strategy buttons sit in the header bar on laptops, tablets and smart boards;
   on phones they drop to their own row under the title. */
.topbar {
  flex-wrap: wrap;
}

.topbar .strategy-row {
  width: auto;
  max-width: none;
  margin: 0;
  flex: 0 1 auto;
}

@media (max-width: 759px), (max-height: 559px) {
  .topbar .strategy-row {
    order: 3;
    flex-basis: 100%;
  }
}

@media (max-width: 759px), (max-height: 559px) {
  .think-line,
  .feedback:not(:empty) {
    height: 3.6rem;
  }
}

/* Short screens (projectors, small laptops): trim padding so tall problems fit. */
@media (min-width: 760px) and (max-height: 720px) {
  .board-panel {
    padding: 10px 12px;
    gap: 4px;
  }
  .think-line,
  .feedback:not(:empty) {
    height: 3.4rem;
  }
  .layout {
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

/* Phones: slimmer header, strategy row, and tabs so the number pad stays
   above Safari's floating address bar. */
@media (max-width: 600px) {
  .topbar {
    padding: 6px 16px;
    gap: 6px 12px;
  }
  .master-logo {
    width: 34px;
    height: 34px;
  }
  .topbar h1 {
    font-size: 1.15rem;
  }
  .mute-btn {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }
  .topbar .strategy-row {
    padding: 3px;
  }
  .strategy-btn {
    min-height: 32px;
    padding: 4px 12px;
  }
  .mode-tab {
    min-height: 40px;
    padding: 6px 12px;
  }
  .layout {
    gap: 10px;
    padding-top: 10px;
  }
  .side-panel {
    gap: 10px;
  }
  .panel-card {
    padding: 12px;
  }
}

/* Phones: in a lesson, the number pad (on "Now you try" steps) and the
   Back / Play / Next buttons come right under the tabs, so they're always on
   screen; the lesson text follows below. */
@media (max-width: 759px), (max-height: 559px) {
  #teachKeypadSlot {
    order: -2;
  }
  .teach-nav {
    order: -1;
  }
}

/* ---------- Area model ---------- */

.board.area-mode {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: calc(var(--cell) * 0.9);
}

.board-stack {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--cell));
  row-gap: var(--row-gap, 4px);
  /* Lines up with the model's first row of boxes, under the problem title. */
  margin-top: calc(var(--cell) * 1.2);
}

.area-part {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.area-title {
  height: calc(var(--cell) * 1.2);
  display: flex;
  align-items: center;
  font-size: calc(var(--cell) * 0.62);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.area-digit {
  padding: 0 0.12em;
  border-radius: 8px;
}

.area-digit.hl {
  background: var(--hl);
  box-shadow: inset 0 0 0 2px #e6c84f;
}

.area-digit.hl-bottom {
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 2px var(--blue);
}

.area-times {
  margin: 0 0.35em;
  color: var(--muted);
}

.area-grid {
  display: grid;
  grid-template-rows: calc(var(--cell) * 0.95);
  grid-auto-rows: calc(var(--cell) * 1.3);
}

.area-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.5);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border-radius: 8px;
}

.area-edge {
  color: var(--accent);
}

.area-edge.hl {
  background: var(--hl);
  color: var(--text);
}

.area-edge.hl-bottom {
  background: var(--blue-soft);
  color: var(--text);
}

.area-box {
  border: 2px solid var(--text);
  border-radius: 0;
  margin: -1px 0 0 -1px;
  background: #fffdfa;
}

.area-cell.active {
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 3px var(--blue);
}

.area-box.source {
  background: var(--hl);
}

.area-slot {
  display: inline-block;
  width: 0.72em;
  height: 1.05em;
  margin-left: 2px;
  border: 2px solid var(--blue);
  border-radius: 4px;
  background: #fff;
  text-align: center;
  line-height: 1;
  animation: pulse 1.4s ease-in-out infinite;
}

.area-slot.wrong {
  border-color: var(--danger);
  background: #fbe9e8;
  color: var(--danger);
  animation: shake 0.35s ease;
}

/* When there isn't room beside the model (phones, narrow screens), script.js
   puts the list underneath it instead. */
.board.area-mode.area-vertical {
  flex-direction: column;
  align-items: center;
}

.board.area-vertical .board-stack {
  margin-top: 0;
}

/* Phones: every strategy name stays visible — smaller buttons that wrap to a
   second row when they don't all fit (no hidden sideways scrolling). */
@media (max-width: 600px) {
  .topbar .strategy-row {
    flex-wrap: wrap;
    justify-content: center;
    overflow-x: visible;
  }
  .strategy-btn {
    font-size: 0.8rem;
    padding: 4px 10px;
  }
}

/* ---------- Lattice ---------- */

.board.lattice-mode {
  display: flex;
  justify-content: center;
}

.lattice {
  display: grid;
  font-variant-numeric: tabular-nums;
}

/* A thin line from the top-right corner to the bottom-left corner. */
.lat-box,
.lat-ext {
  position: relative;
  background: linear-gradient(to bottom right,
    transparent calc(50% - 1px), var(--accent) calc(50% - 1px),
    var(--accent) calc(50% + 1px), transparent calc(50% + 1px));
}

.lat-box {
  border: 2px solid var(--text);
  margin: -1px 0 0 -1px;
  background-color: #fffdfa;
}

.lat-box.current {
  background-color: var(--blue-soft);
}

.lat-ext {
  opacity: 1;
  background: linear-gradient(to bottom right,
    transparent calc(50% - 1px), var(--line) calc(50% - 1px),
    var(--line) calc(50% + 1px), transparent calc(50% + 1px));
}

.lat-factor {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.62);
  font-weight: 800;
  border-radius: 10px;
}

.lat-factor.hl {
  background: var(--hl);
  box-shadow: inset 0 0 0 2px #e6c84f;
}

.lat-factor.hl-bottom {
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 2px var(--blue);
}

/* Digits inside a box: tens in the top-left half, ones in the bottom-right half. */
.lat-digit,
.lat-answer {
  position: absolute;
  width: calc(var(--cell) * 0.56);
  height: calc(var(--cell) * 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.5);
  font-weight: 800;
  border-radius: 6px;
}

.lat-tens {
  top: calc(var(--cell) * 0.12);
  left: calc(var(--cell) * 0.12);
}

.lat-ones {
  bottom: calc(var(--cell) * 0.12);
  right: calc(var(--cell) * 0.12);
}

/* Answer squares: under a column the digit sits in the top-left half; beside
   a row it sits in the bottom-right half (where that diagonal comes out). */
.lat-ext-bottom .lat-answer {
  top: calc(var(--cell) * 0.12);
  left: calc(var(--cell) * 0.12);
}

.lat-ext-left .lat-answer {
  bottom: calc(var(--cell) * 0.12);
  right: calc(var(--cell) * 0.12);
}

.lat-answer {
  color: var(--blue);
  font-size: calc(var(--cell) * 0.56);
}

.lat-digit.empty {
  visibility: hidden;
}

.lat-digit.active,
.lat-answer.active {
  border: 3px solid var(--blue);
  background: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}

.lat-digit.wrong,
.lat-answer.wrong {
  border-color: var(--danger);
  background: #fbe9e8;
  color: var(--danger);
  animation: shake 0.35s ease;
}

.lat-digit.hl {
  background: var(--hl);
  box-shadow: 0 0 0 2px #e6c84f;
}

.lat-carry-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.carry-box.lat-carry {
  width: calc(var(--cell) * 0.56);
  height: calc(var(--cell) * 0.56);
  font-size: calc(var(--cell) * 0.4);
}

@media (max-width: 600px) {
  .topbar .strategy-row {
    gap: 2px;
    padding: 2px;
  }
  .strategy-btn {
    min-height: 28px;
    padding: 2px 10px;
    font-size: 0.78rem;
  }
}

/* Lattice: top and side numbers fade while the diagonals are being added. */
.lat-factor.muted {
  color: #cdbfb2;
  transition: color 0.3s ease;
}

/* Standard algorithm / partial products: the top and bottom numbers fade
   while the rows are being added. */
.cell.factor.muted {
  color: #cdbfb2;
  transition: color 0.3s ease;
}

/* ---------- Break apart ---------- */

.board.break-mode {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: calc(var(--cell) * 0.9);
}

.board.break-mode.break-vertical {
  flex-direction: column;
  align-items: center;
}

.board.break-mode .board-stack {
  margin-top: calc(var(--cell) * 1.1);
}

.board.break-vertical .board-stack {
  margin-top: 0;
}

.break-eq {
  display: flex;
  flex-direction: column;
  gap: calc(var(--cell) * 0.18);
  font-size: calc(var(--cell) * 0.56);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  max-width: calc(var(--cell) * 16);
}

.eq-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--cell) * 0.12) calc(var(--cell) * 0.16);
  min-height: calc(var(--cell) * 0.9);
}

.eq-line:first-child {
  font-size: 1.25em;
}

.eq-term {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--cell) * 0.16);
}

.eq-op,
.eq-paren {
  color: var(--muted);
}

.eq-digit {
  padding: 0 0.1em;
  border-radius: 8px;
}

.eq-digit.hl,
.eq-pair.hl {
  background: var(--hl);
  box-shadow: inset 0 0 0 2px #e6c84f;
  border-radius: 8px;
}

.eq-digit.hl-bottom {
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 2px var(--blue);
}

.eq-pair {
  font-weight: 700;
  color: var(--accent);
  padding: 0 0.15em;
  white-space: nowrap;
}

.eq-num {
  display: inline-flex;
  align-items: center;
  min-width: 1.2em;
  min-height: 1.3em;
  padding: 0 0.15em;
  border-radius: 6px;
  white-space: nowrap;
}

.eq-num.blank {
  border: 2px dashed var(--line);
  min-width: 1.6em;
}

.eq-num.active {
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 2px var(--blue);
}

.eq-answer {
  color: var(--success);
}

.eq-number {
  display: inline-flex;
}

.eq-term .eq-paren {
  margin: 0 -0.05em;
}

/* Typed numbers only need padding while they're a box (blank or being typed). */
.eq-num:not(.blank):not(.active) {
  padding: 0;
  min-width: 0;
}

/* Break apart: the product being copied into the list glows. */
.eq-num.source {
  background: var(--hl);
  box-shadow: inset 0 0 0 2px #e6c84f;
}
