/* CPA widgets — mobile-first, Foundation targets ≥56px */

.teach-overlay.teach-interactive .teach-modal {
  width: min(720px, 98vw);
  max-height: min(94vh, 680px);
}
.teach-overlay.teach-interactive.band-foundation .teach-modal h2 {
  font-size: clamp(18px, 3.4vw, 24px);
}

.cpa-lesson {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.cpa-q {
  margin: 0;
  font-size: clamp(16px, 3.2vw, 20px);
  color: #e2e8f0;
  line-height: 1.3;
}
.cpa-q strong { color: #fff; }
.cpa-step-label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #86efac;
}
.cpa-prompt {
  margin: 0;
  font-size: clamp(17px, 3.4vw, 22px);
  font-weight: 700;
  color: #fefce8;
  line-height: 1.3;
}
.cpa-widget { min-height: 88px; }
.cpa-feedback {
  min-height: 1.4em;
  margin: 4px 0 0;
  font-size: 15px;
  color: #cbd5e1;
}
.cpa-feedback.is-ok { color: #86efac; }
.cpa-feedback.is-trap,
.cpa-feedback.is-miss { color: #fde68a; }
.cpa-feedback.is-info { color: #93c5fd; }

.mh-widget {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.mh-widget.is-locked { opacity: 0.72; pointer-events: none; }
.mh-hit {
  min-width: 56px;
  min-height: 56px;
}

/* Number pad */
.np-pad { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.np-readout {
  min-width: 120px;
  min-height: 52px;
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid rgba(250, 204, 21, 0.45);
  color: #fefce8;
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.06em;
}
.np-grid {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 8px;
}
.np-key {
  border: 0;
  border-radius: 12px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}
/* Pad with a minus and/or point key: those sit in a 4th column, next to delete. */
.np-grid.np-grid-4 { grid-template-columns: repeat(4, 64px); }
.np-grid-4 .np-wide { grid-column: span 2; }
.np-grid-4 .np-tall { grid-row: span 2; }
.np-key:active { transform: scale(0.96); background: #334155; }
.np-ok { background: #166534; color: #ecfccb; }
.np-del { background: #7f1d1d; }

/* Ten-frame */
.tf-board { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.tf-stats { color: #e2e8f0; font-size: 16px; font-weight: 700; }
.tf-frames { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.tf-frame {
  display: grid;
  grid-template-columns: repeat(5, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 4px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(148, 163, 184, 0.45);
}
.tf-cell {
  border: 2px dashed rgba(148, 163, 184, 0.55);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.4);
  padding: 0;
  cursor: pointer;
}
.tf-cell.has-gold,
.tf-cell.has-blue { border-style: solid; }
.tf-dot {
  display: block;
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
}
.tf-dot.gold { background: #facc15; border-color: #fef08a; }
.tf-dot.blue { background: #60a5fa; border-color: #bfdbfe; }
.tf-dot.away { width: 28px; height: 28px; background: rgba(248, 113, 113, 0.85); border-color: #fecaca; }
.tf-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.tf-add {
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  background: #334155;
  color: #f8fafc;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.tf-add.gold { background: #a16207; }
.tf-add.blue { background: #1d4ed8; }
.tf-add.ghost { background: #1e293b; }
.tf-away-lab {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fca5a5;
}
.tf-away {
  min-height: 40px;
  min-width: 160px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 2px dashed #f87171;
  background: rgba(127, 29, 29, 0.25);
}

/* Jump line */
.jl-line { display: flex; flex-direction: column; gap: 8px; }
.jl-status { text-align: center; color: #e2e8f0; font-weight: 700; }
.jl-track {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 2px 10px;
  -webkit-overflow-scrolling: touch;
}
.jl-tick {
  flex: 0 0 52px;
  border: 0;
  border-radius: 10px;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.jl-tick.is-known { background: #334155; color: #fde68a; }
.jl-tick.is-start { outline: 2px solid #facc15; }
.jl-tick.is-landed { background: #166534; color: #dcfce7; }
.jl-tick.is-here { background: #2563eb; color: #fff; }

/* Dot array */
.da-board { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.da-status { color: #e2e8f0; font-weight: 700; }
.da-grid { display: grid; gap: 6px; justify-content: center; }
.da-cell {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px dashed #93c5fd;
  background: transparent;
  cursor: pointer;
}
.da-cell.is-on {
  border-style: solid;
  background: #facc15;
  border-color: #fef08a;
}

/* Group bowls */
.gb-board { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.gb-row { display: flex; gap: 10px; justify-content: center; padding: 4px; }
.gb-bin {
  min-width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(148, 163, 184, 0.4);
}
.gb-dots {
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}
.gb-n { color: #fefce8; font-weight: 800; }

/* Share circles */
.sc-board { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sc-status { color: #e2e8f0; font-weight: 700; }
.sc-pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 420px; }
.sc-dot {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 3px solid #fef08a;
  background: #facc15;
  cursor: pointer;
}
.sc-dot.is-picked { box-shadow: 0 0 0 3px #38bdf8; }
.sc-dot.is-grouped {
  background: #4ade80;
  border-color: #bbf7d0;
  opacity: 0.85;
}

.band-foundation .mh-hit {
  min-width: 56px;
  min-height: 56px;
}

/* Shared column working (kid types, Etheral carries) */
.cb-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: flex-start;
}
.cb-board { min-width: min(100%, 280px); }
.cb-live {
  margin: 0 0 8px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: #fefce8;
}
.cb-carry {
  min-height: 28px;
  border-style: dashed;
  background: transparent;
}
.cb-carry .place-digit { font-size: 16px; color: #facc15; }
.cb-carry.is-on {
  border-style: solid;
  border-color: rgba(250, 204, 21, 0.7);
  background: rgba(161, 98, 7, 0.35);
  animation: cb-pop 0.35s ease-out;
}
@keyframes cb-pop {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.place-cell.is-borrow .place-digit { color: #fde68a; }
.place-cell.is-wide .place-digit { font-size: 18px; letter-spacing: -0.04em; }
.cb-point {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 28px;
  font-weight: 900;
  color: #facc15;
  padding-bottom: 4px;
}
.cb-pad { margin-top: 4px; }

.tw-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.tw-hist { width: 100%; max-width: 360px; }
.tw-done-line {
  margin: 0 0 4px;
  color: #86efac;
  font-weight: 700;
  text-align: center;
}
.tw-ask {
  margin: 0;
  max-width: 420px;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
  color: #fefce8;
}
.tw-note {
  margin: 0;
  min-height: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  color: #facc15;
}
.tw-note:empty { display: none; }
.tw-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.tw-expr {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 800;
  color: #f8fafc;
}
.tw-box {
  min-width: 88px;
  min-height: 52px;
  padding: 6px 14px;
  border-radius: 12px;
  border: 2px solid rgba(250, 204, 21, 0.55);
  background: rgba(15, 23, 42, 0.9);
  color: #fefce8;
  font-size: 28px;
  font-weight: 800;
  text-align: center;
}

@media (orientation: landscape) and (max-height: 430px) {
  .np-readout { min-height: 40px; font-size: 24px; }
  .np-grid { grid-template-columns: repeat(3, 52px); gap: 6px; }
  .np-grid.np-grid-4 { grid-template-columns: repeat(4, 52px); }
  /* Typed working on a phone: the sum on the left, the number pad beside it (like the column
     board), so every key is on screen without scrolling. */
  .tw-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 14px;
    row-gap: 6px;
    align-items: center;
    justify-items: center;
  }
  .tw-wrap > * { grid-column: 1; }
  .tw-wrap > .np-grid {
    grid-column: 2;
    grid-row: 1 / span 4;
    align-self: start;
    margin-top: 0;
    /* Long working scrolls; the pad stays put beside it. */
    position: sticky;
    top: 0;
  }
  .cpa-lesson { gap: 4px; }
  .np-key, .mh-hit, .tf-cell, .jl-tick, .da-cell {
    min-width: 48px;
    min-height: 44px;
  }
  .tf-frame {
    grid-template-columns: repeat(5, 40px);
    grid-template-rows: repeat(2, 40px);
  }
  .tf-dot { width: 28px; height: 28px; }
  .da-cell { width: 44px; height: 44px; }
  .cpa-prompt { font-size: 16px; }
}

html.teach-interactive-open .touch-controls {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden;
}

/* Long division bracket (16 Nov): the answer builds on top, one digit per solved step. */
.tw-bracket {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: end;
  column-gap: 8px;
  font-weight: 800;
  color: #f8fafc;
}
.tw-q-row, .tw-dividend { display: flex; }
.tw-q-cell, .tw-d-cell {
  width: clamp(30px, 6vw, 40px);
  text-align: center;
  font-size: clamp(24px, 5vw, 34px);
  line-height: 1.25;
}
.tw-q-cell { min-height: 1.25em; color: #94a3b8; }
.tw-q-cell.is-set { color: #86efac; }
.tw-q-cell.is-next {
  color: #facc15;
  border-radius: 8px;
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.6);
  animation: twQNext 1.1s ease-in-out infinite;
}
.tw-divisor { font-size: clamp(24px, 5vw, 34px); line-height: 1.25; padding-right: 6px; color: #fde68a; }
.tw-dividend { border-top: 3px solid #f8fafc; border-left: 3px solid #f8fafc; border-top-left-radius: 8px; padding-left: 4px; }
.tw-bracket.is-done .tw-q-cell { color: #4ade80; }
@keyframes twQNext { 0%, 100% { box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.35); } 50% { box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.9); } }
@media (orientation: landscape) and (max-height: 430px) {
  .tw-q-cell, .tw-d-cell, .tw-divisor { font-size: 22px; width: 28px; }
}

/* Long multiplication answer rows (16 Nov) */
.tw-rows { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.tw-prod-row { display: flex; align-items: center; gap: 10px; }
.tw-prod-label { font-size: clamp(18px, 3.6vw, 24px); font-weight: 800; color: #fde68a; white-space: nowrap; }
.tw-prod-row.is-full .tw-q-cell { color: #4ade80; }
.tw-prod-row .tw-q-row { border-bottom: 3px solid rgba(248, 250, 252, 0.8); }


/* Column sums inside the working (20 Nov): 252 + 280 written as a real column sum. */
.tw-stack { display: inline-flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.tw-stack-row { display: flex; align-items: center; }
.tw-stack-op { width: 1em; text-align: center; font-size: clamp(22px, 4.6vw, 30px); font-weight: 800; color: #fde68a; }
.tw-s-cell { color: #f8fafc; font-weight: 800; border-radius: 6px; }
.tw-stack-row.is-carry .tw-s-cell { font-size: clamp(14px, 2.8vw, 18px); line-height: 1; min-height: 1em; color: #facc15; }
.tw-stack-row.is-bot { border-bottom: 3px solid rgba(248, 250, 252, 0.85); }
.tw-stack-row.is-ans .tw-s-cell { color: #94a3b8; }
.tw-stack-row.is-ans .tw-s-cell.is-set { color: #86efac; }
.tw-stack.is-full .tw-stack-row.is-ans .tw-s-cell { color: #4ade80; }
.tw-s-cell.is-live { background: rgba(250, 204, 21, 0.16); }
.tw-s-cell.gave-1 { text-decoration: line-through; text-decoration-color: #f87171; text-decoration-thickness: 2px; }
.tw-s-cell.got-10::before { content: "1"; font-size: 0.55em; color: #facc15; vertical-align: super; }
@media (orientation: landscape) and (max-height: 430px) {
  .tw-stack-op { font-size: 20px; }
  .tw-stack-row.is-carry .tw-s-cell { font-size: 13px; }
}
/* Phone on its side: the answer rows already hold the results, so only the last two worked lines
   stay listed and the step being typed is not pushed off the screen. */
@media (orientation: landscape) and (max-height: 520px) {
  .tw-hist .tw-done-line:nth-last-child(n+3) { display: none; }
  .tw-wrap.stack-live .tw-hist,
  .tw-wrap.stack-live .tw-rows > :not(.is-live-stack) { display: none; }
  .tw-wrap { row-gap: 4px; }
}

/* Typed working shows its own step line, so the lesson's header prompt is not repeated above it. */
.cpa-lesson:has(.tw-wrap) .cpa-prompt { display: none; }

/* Key pressed on a computer keyboard */
.np-key.is-key { transform: scale(0.94); filter: brightness(1.35); }

/* Computer screens: the working on the left and the number pad beside it, so the pad is never
   below the fold (the keyboard types into it too). */
@media (orientation: landscape) and (min-width: 900px) and (min-height: 521px) {
  .tw-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 22px;
    row-gap: 8px;
    align-items: center;
    justify-items: center;
  }
  .tw-wrap > * { grid-column: 1; }
  .tw-wrap > .np-grid { grid-column: 2; grid-row: 1 / span 5; align-self: start; margin-top: 0; position: sticky; top: 0; }
  .tw-hist .tw-done-line:nth-last-child(n+5) { display: none; }
  .tw-wrap.stack-live .tw-hist,
  .tw-wrap.stack-live .tw-rows > :not(.is-live-stack) { display: none; }
}
