/* The step runner: animated algorithm workspace (tableau), phase stepper,
   question panel, feedback, and results. */

.runner { display: flex; flex-direction: column; gap: 1rem; }

.runner-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  box-shadow: var(--shadow);
}

.runner-progress { padding: 0 0.25rem; }

/* --- phase stepper --------------------------------------------------------- */

.stepper {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.4rem 0.15rem 0.6rem;
  scrollbar-width: thin;
}
.step-chip {
  flex: 0 0 auto;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.step-chip.current { border-color: var(--role-focus); color: #1d4ed8; background: #eff6ff; }
.step-chip.done { border-color: #86efac; color: #15803d; background: #f0fdf4; }
.step-chip { font-family: inherit; }
.step-chip.clickable { cursor: pointer; }
.step-chip.clickable:hover { border-color: var(--primary); }

/* --- replay controls (debugger-style stepping) ------------------------------ */

.replay-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-sm { padding: 0.45rem 0.85rem; font-size: 0.9rem; }

/* --- addend provenance chips ("12 ← 4 × 3" + "1 ← carried") ------------------ */

.addends {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.addend-op { font-weight: 800; font-size: 1.2rem; color: var(--text-muted); }
.addend-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 10px;
  padding: 0.3rem 0.7rem;
  border: 2px solid var(--border);
}
.addend-focus { border-color: var(--role-focus); background: #eff6ff; }
.addend-value { font-size: 1.15rem; font-weight: 800; line-height: 1.1; }
.addend-label { font-size: 0.72rem; font-weight: 600; opacity: 0.8; }

/* --- the algorithm workspace (tableau) -------------------------------------- */

.workspace {
  display: flex;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
  min-height: 9rem;
}

/* --- the problem banner (the original problem, above the workspace) --------- */

.problem-banner {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  font-size: 1.6rem;
  font-weight: 800;
  /* The banner sits inside the workspace stage now: keep breathing room
     between the problem and the tableau below it. */
  margin-bottom: 1rem;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.25s, box-shadow 0.25s;
}
.problem-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.problem-banner.banner-focus {
  border-color: var(--role-focus);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.16);
}

/* --- the calculator's problem-entry form (inside the banner) ---------------------- */

.problem-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.problem-entry .problem-label {
  margin-right: 0.25rem;
}
.problem-input {
  width: 6.5rem;
  padding: 0.35rem 0.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: inherit;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: 8px;
}
.problem-entry-op { font-size: 1.4rem; font-weight: 800; }
.problem-entry-error {
  width: 100%;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 1.1em;
  text-align: center;
}

.tableau {
  position: relative;
  display: grid;
  grid-template-columns: 4.2rem repeat(var(--places, 4), 3.3rem);
  gap: 5px;
}

/* Side-by-side composite states: a narrow divider column splits the left
   panel from the right one. */
.tableau.t-composite {
  grid-template-columns:
    4.2rem
    repeat(var(--div-col, 0), 3.3rem)
    0.9rem
    repeat(calc(var(--places, 4) - var(--div-col, 0) - 1), 3.3rem);
}
.t-vline {
  width: 0;
  margin: 0 auto;
  border-left: 1.5px dashed var(--border);
}

.t-cell {
  height: 3.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  transition: border-color 0.25s, background 0.25s, color 0.25s, box-shadow 0.25s, opacity 0.25s;
}
.t-cell.empty { background: #fafbff; border-color: #eef2f6; color: transparent; }
.t-cell[data-role="focus"] {
  border-color: var(--role-focus);
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.16);
}
.t-cell[data-role="ask"] {
  border: 2px dashed var(--role-ask);
  background: #fffbeb;
  color: #b45309;
}
.t-cell[data-role="done"] {
  border-color: #86efac;
  background: #f0fdf4;
  color: #15803d;
}
.t-cell[data-role="muted"] {
  border-color: #eef2f6;
  background: #fafbff;
  opacity: 0.7;
}
.t-cell.flash-error { animation: cell-error 0.5s ease-out; }
@keyframes cell-error {
  0%, 100% { background: var(--surface); }
  30% { background: #fee2e2; border-color: var(--role-error); }
}

.t-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-muted);
}
.t-line { border-top: 2.5px solid #475569; margin-top: -2px; }

/* Cells with a small label above the value (area-model boxes: "40 × 20"). */
.t-cell.has-label { flex-direction: column; font-size: 1.15rem; }
.t-cell-label { font-size: 0.68rem; font-weight: 700; opacity: 0.8; line-height: 1.1; }

/* In-cell digit inputs (blank-paper experiment): the student writes the
   answer directly into the workspace boxes. */
.cell-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  padding: 0;
  margin: 0;
  outline: none;
}
.cell-input:focus { box-shadow: inset 0 0 0 3px rgba(59, 130, 246, 0.35); border-radius: 8px; }
.cell-input:disabled { opacity: 1; }
.cell-input.cell-correct { color: #15803d; }
.cell-input.cell-shake { animation: input-shake 0.4s ease-in-out; }

/* A crossed-out digit (un-grouping in subtraction): the old digit is struck
   through and faded, the new digit is written beside it. */
.t-strike {
  font-size: 0.72em;
  opacity: 0.5;
  text-decoration: line-through;
  margin-right: 0.15rem;
}

/* A marker after a cell's value (long division's "4 |" divider). */
.t-suffix {
  font-weight: 700;
  color: #64748b;
  margin-left: 0.12rem;
}

/* The final-answer form in the question panel. */
.final-label { font-weight: 700; margin-right: 0.55rem; white-space: nowrap; }
.final-sep { font-weight: 700; margin: 0 0.35rem; }
.final-input { max-width: 8rem; }

/* Mode selection on the home screen. */
.mode-pick {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  max-width: 640px;
  margin: 0 auto;
}
.mode-card {
  text-align: left;
  padding: 1.4rem;
  border-radius: 14px;
  background: #fff;
  border: 2px solid #e2e8f0;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.mode-card:hover { transform: translateY(-2px); border-color: #6366f1; }
.mode-icon { font-size: 2rem; margin-bottom: 0.4rem; }
.mode-card h2 { margin: 0 0 0.3rem; font-size: 1.25rem; }
.mode-card p { margin: 0; color: #64748b; font-size: 0.95rem; }

/* Digit dropdowns on the activity page. */
.digit-picker {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}
.digit-select {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  border: 2px solid #e2e8f0;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
}
.digit-op { font-size: 1.3rem; font-weight: 700; color: #6366f1; }
.badge-row { display: flex; gap: 0.5rem; margin: 0.6rem 0 0.2rem; }

/* Explicit boxes in the long-division box method. */
.t-cell.box-cell { border: 2px solid #94a3b8; border-radius: 6px; }

/* Tiny header text (place-value labels). */
.t-cell.t-tiny { font-size: 0.58rem; opacity: 0.75; }

/* Overwrite input (subtraction borrows): the write-in box sits ABOVE the
   digit being replaced, which stays visible beneath it. */
.t-cell.cell-overwrite {
  flex-direction: column;
  gap: 1px;
}
.t-cell.cell-overwrite .cell-input {
  background: #fff;
  border: 2px solid #f59e0b;
  border-radius: 6px;
  width: 100%;
  min-height: 1.6rem;
}
.t-cell.cell-overwrite .cell-input:focus {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
}

/* Bare header cells (dimension labels) — unboxed until focused/asked/done. */
.t-header {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  color: var(--text-muted) !important;
  font-weight: 800;
  font-size: 1.1rem;
}

/* --- color legend ---------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
}
.legend-item { display: flex; align-items: center; gap: 0.35rem; }
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid var(--border);
}
.legend-swatch.focus { background: #eff6ff; border-color: var(--role-focus); }
.legend-swatch.ask { background: #fffbeb; border-color: var(--role-ask); border-style: dashed; }
.legend-swatch.done { background: #f0fdf4; border-color: #86efac; }

/* --- question panel & feedback ---------------------------------------------- */

.question-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow);
}
.step-caption { color: var(--text-muted); font-size: 0.95rem; font-weight: 600; margin-bottom: 0.4rem; }
.step-caption.replay { text-align: center; font-size: 1.05rem; }
.step-prompt { font-size: 1.35rem; font-weight: 700; margin-bottom: 0.9rem; }

.answer-form { display: flex; gap: 0.6rem; align-items: stretch; flex-wrap: wrap; }
.answer-input {
  flex: 1;
  min-width: 8rem;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  color: var(--text);
  background: #ffffff;
}
.answer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}
.answer-input:disabled { background: #f1f5f9; }
.answer-input.answer-correct { border-color: #86efac; background: #f0fdf4; color: #15803d; }
.answer-input.answer-shake { animation: input-shake 0.4s ease-in-out; border-color: var(--role-error); }
@keyframes input-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}
.answer-error {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem; }
.choice-btn {
  border: 2px solid var(--border);
  background: #ffffff;
  border-radius: 12px;
  padding: 0.8rem;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.choice-btn:hover { border-color: var(--primary); }
.choice-btn:disabled { opacity: 0.6; cursor: default; }
.choice-btn.choice-correct { border-color: #86efac; background: #f0fdf4; color: #15803d; }
.choice-shake { animation: input-shake 0.4s ease-in-out; }

/* Tap-a-cell questions: the candidate cells are clickable. */
.t-cell.tap-target { cursor: pointer; border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35); }
.t-cell.tap-target:hover { background: #dbeafe; }
.t-cell.tap-wrong { animation: input-shake 0.4s ease-in-out; border-color: var(--role-error); }
.t-cell.tap-correct { border-color: #16a34a; background: #dcfce7; }

/* --- drawing overlay (palette of tools drawing over the workspace) ---------------- */

.workspace-stage {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.draw-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.draw-toolbar-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 0.25rem;
}
.draw-toolbar .btn-active { border-color: var(--primary); color: #fff; background: var(--primary); }

.draw-canvas-wrap {
  position: relative;
  flex: 1;
}
/* The canvas covers the WHOLE runner (header, stepper, problem, tableau,
   panel) so the pen can write anywhere on the page, margins included. The
   toolbar sits above it and stays clickable while drawing. */
canvas.draw-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 30;
  touch-action: none; /* draw instead of scrolling */
}
.draw-toolbar { position: relative; z-index: 40; }

/* --- the pen color picker --------------------------------------------------------- */

.draw-color-picker { position: relative; display: inline-flex; }
.draw-color-dot {
  display: inline-block;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.3);
  vertical-align: middle;
}
.draw-color-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 7.5rem;
}
.draw-color-menu.open { display: flex; }
.draw-color-swatch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  background: transparent;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: capitalize;
}
.draw-color-swatch:hover { background: #f1f5f9; }

.feedback { min-height: 2.6rem; }
.feedback:not(:empty) { margin-top: 0.4rem; }
.feedback-correct { color: var(--success); font-weight: 700; font-size: 1.05rem; }
.explain {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  line-height: 1.45;
  margin-top: 0.6rem;
}
.explain-wrong { background: #fff7ed; border-color: #fed7aa; }

/* --- results / end screens -------------------------------------------------- */

.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}
.results-title { font-size: 1.6rem; font-weight: 800; }
.results-sub { color: var(--text-muted); }
.results-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 0.6rem;
}

