/* Lesson page: chalkboard stage, marble animation, chalk notes, controls. */

.lesson {
  padding-top: 10px;
}

/* ---------- top bar & tabs ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 0 12px;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.kicker {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--brand-deep);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  line-height: 1.15;
}

#sound-toggle .icon-off,
#sound-toggle.is-off .icon-on {
  display: none;
}

#sound-toggle.is-off .icon-off {
  display: block;
}

@media (prefers-color-scheme: dark) {
  .kicker {
    color: var(--brand);
  }
}

@media (max-width: 640px) {
  .brand span {
    display: none;
  }

  .topbar-title {
    text-align: left;
  }
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 6px;
  margin-bottom: 14px;
  background: var(--bg-accent);
  border-radius: 18px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 8px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 700;
  cursor: pointer;
}

.tab b {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--line);
  color: var(--ink);
  font-size: 0.9rem;
}

.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--line);
}

.tab.is-active b {
  background: var(--brand);
  color: #fff;
}

@media (max-width: 420px) {
  .tab {
    flex-direction: column;
    gap: 2px;
    font-size: 0.9rem;
    line-height: 1.1;
  }
}

/* ---------- chalkboard ---------- */

.board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  align-items: center;
  gap: 8px 22px;
  min-height: 320px;
  padding: clamp(10px, 2.2vw, 22px);
  border: 12px solid var(--board-wood);
  border-radius: 24px;
  background:
    radial-gradient(ellipse at 18% 12%, rgba(255, 255, 255, 0.07), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(255, 255, 255, 0.05), transparent 45%),
    var(--board);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.25),
    inset 0 0 50px rgba(0, 0, 0, 0.35),
    0 8px 0 var(--board-wood-deep),
    var(--shadow-soft);
  color: var(--chalk);
  overflow: hidden;
}

@media (max-width: 760px) {
  .board {
    grid-template-columns: 1fr;
    border-width: 8px;
    border-radius: 20px;
  }
}

.marble-board {
  width: 100%;
  height: auto;
  overflow: visible;
}

.no-anim,
.no-anim * {
  transition: none !important;
  animation: none !important;
}

.frames {
  opacity: 0;
  transition: opacity 400ms ease;
}

.frames.is-shown {
  opacity: 1;
}

.frame rect {
  fill: rgba(255, 255, 255, 0.04);
  stroke: rgba(244, 241, 232, 0.8);
  stroke-width: 3;
}

.frame line {
  stroke: rgba(244, 241, 232, 0.35);
  stroke-width: 2;
  stroke-dasharray: 4 6;
  stroke-linecap: round;
}

.frame-label,
.pouch-label,
.pouch-badge {
  font-family: var(--font-chalk);
  fill: var(--chalk);
}

.frame-label {
  font-size: 44px;
  opacity: 0;
  transition: opacity 400ms ease;
}

.frame-label.is-shown,
.pouch-badge.is-shown {
  opacity: 1;
}

.frame-label[data-tone="tens"] {
  fill: var(--c-tens);
}

.frame-label[data-tone="ones"] {
  fill: var(--c-ones);
}

.frame-label[data-tone="result"] {
  fill: var(--c-result);
}

.pouch,
.jar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms ease;
}

.pouch.is-shown,
.jar.is-shown {
  opacity: 1;
  pointer-events: auto;
}

.jar-lid {
  fill: #c0563b;
  stroke: #8a3420;
  stroke-width: 3;
}

.jar-glass {
  fill: rgba(190, 225, 255, 0.12);
  stroke: rgba(225, 242, 255, 0.75);
  stroke-width: 3;
}

.jar-shine {
  fill: none;
  stroke: rgba(255, 255, 255, 0.3);
  stroke-width: 6;
  stroke-linecap: round;
}

.jar.is-calling {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: jar-bounce 1.1s ease-in-out infinite;
}

@keyframes jar-bounce {
  0%,
  60%,
  100% {
    transform: none;
  }

  25% {
    transform: translateY(-10px) scale(1.04);
  }
}

/* Game: everything tappable shows a hand cursor. */
.marble-board.is-interactive .marble:not(.is-hidden),
.marble-board.is-interactive .jar,
.marble-board.is-interactive .frame {
  cursor: pointer;
}

.marble-board {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pouch-bag {
  fill: #b9773f;
  stroke: #7b4a22;
  stroke-width: 3;
}

.pouch-string {
  fill: none;
  stroke: #f0d3a2;
  stroke-width: 4;
  stroke-linecap: round;
}

.pouch-label {
  font-size: 32px;
  text-anchor: middle;
}

.pouch-badge {
  font-size: 32px;
  text-anchor: middle;
  fill: var(--c-take);
  opacity: 0;
  transition: opacity 400ms ease;
}

/* Marble: outer <g> = position, .marble-pop = appear/fade, .marble-spin = rolling. */
.marble,
.marble-spin {
  transition: transform 700ms cubic-bezier(0.3, 1.2, 0.5, 1) var(--delay, 0ms);
}

.marble-pop,
.marble-spin {
  transform-box: view-box;
  transform-origin: 0 0;
}

.marble-pop {
  transition:
    transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1) var(--pop-delay, 0ms),
    opacity 380ms ease var(--pop-delay, 0ms);
}

/* A bigger invisible circle so small fingers can hit a marble. */
.marble-hit {
  fill: transparent;
}

.marble.is-shaking .marble-pop {
  animation: shake 420ms ease;
}

.marble.is-hidden .marble-pop {
  transform: scale(0);
  opacity: 0;
}

.marble.is-dim .marble-pop {
  opacity: 0.2;
}

.marble-shadow {
  fill: rgba(0, 0, 0, 0.3);
}

.marble-body {
  fill: url(#marble-plain);
}

.tone-tens .marble-body {
  fill: url(#marble-tens);
}

.tone-ones .marble-body {
  fill: url(#marble-ones);
}

.tone-take .marble-body {
  fill: url(#marble-take);
}

.tone-result .marble-body {
  fill: url(#marble-result);
}

.marble-swirl {
  fill: none;
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 3;
  stroke-linecap: round;
}

.marble-shine {
  fill: rgba(255, 255, 255, 0.75);
}

.marble-label {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 24px;
  text-anchor: middle;
  fill: #0f3a1f;
  opacity: 0;
  transition: opacity 260ms ease var(--label-delay, 0ms);
}

.marble.is-counted .marble-label {
  opacity: 1;
}

.marble.is-pulsing .marble-pop {
  animation: marble-pulse 640ms ease-in-out 3;
}

@keyframes marble-pulse {
  50% {
    transform: translateY(-8px) scale(1.15);
  }
}

/* ---------- chalk notes ---------- */

/* min-height reserves room for the finished notes so the page never jumps mid-lesson. */
.board-notes {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-width: 0;
  min-height: calc(7.8em + 130px);
  font-family: var(--font-chalk);
  font-size: clamp(20px, 2.3vw, 28px);
  line-height: 1.25;
}

@media (max-width: 760px) {
  .board-notes {
    min-height: calc(7.8em + 50px);
    padding: 4px 6px 8px;
  }

  /* On phones the frame counts beside the marbles already show the split. */
  .note-bond {
    display: none;
  }
}

.note {
  white-space: nowrap;
}

.note.is-new {
  animation: chalk-write 900ms ease-out backwards;
}

@keyframes chalk-write {
  from {
    clip-path: inset(0 100% 0 0);
  }

  to {
    clip-path: inset(0 0 0 0);
  }
}

.note-problem {
  font-size: 1.45em;
  letter-spacing: 0.02em;
}

.t-tens {
  color: var(--c-tens);
}

.t-ones {
  color: var(--c-ones);
}

.t-take {
  color: var(--c-take);
}

.t-result {
  color: var(--c-result);
}

.num.is-pop {
  display: inline-block;
  animation: num-pop 520ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes num-pop {
  from {
    opacity: 0;
    transform: scale(0.2);
  }
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  margin-right: 0.35em;
  padding: 0.05em 0.6em 0.05em 0.2em;
  border: 2px solid currentColor;
  border-radius: 999px;
  color: var(--c-tag);
  font-family: var(--font-ui);
  font-size: 0.6em;
  font-weight: 700;
  line-height: 1.4;
  vertical-align: 0.2em;
}

.tag b {
  display: inline-grid;
  place-items: center;
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  background: var(--c-tag);
  color: var(--board-deep);
}

.glow-tags .tag {
  animation: tag-glow 700ms ease-in-out calc(var(--i) * 900ms) 2 alternate;
}

@keyframes tag-glow {
  to {
    background: var(--c-tag);
    color: var(--board-deep);
    transform: scale(1.15);
    box-shadow: 0 0 18px rgba(255, 224, 138, 0.65);
  }
}

.blank {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 0.15em;
  border-bottom: 3px dashed var(--chalk-soft);
  border-radius: 4px;
  color: var(--chalk-soft);
  text-align: center;
}

.blank.is-active {
  border-bottom-color: var(--c-tag);
  background: rgba(255, 224, 138, 0.12);
  color: var(--c-tag);
  animation: blank-blink 1.2s ease-in-out infinite;
}

@keyframes blank-blink {
  50% {
    background: rgba(255, 224, 138, 0.3);
  }
}

.blank.is-wrong {
  border-bottom-color: #ff8b8b;
  background: rgba(255, 120, 120, 0.15);
  color: #ff8b8b;
  animation: shake 420ms ease;
}

@keyframes shake {
  20% {
    transform: translateX(-6px);
  }

  40% {
    transform: translateX(6px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(3px);
  }
}

.note.is-glow {
  transform-origin: left center;
  animation: line-glow 900ms ease-in-out 2;
}

@keyframes line-glow {
  50% {
    transform: scale(1.06);
    text-shadow: 0 0 16px rgba(255, 224, 138, 0.9);
  }
}

.answer-box {
  display: inline-block;
  padding: 0.05em 0.6em;
  border: 3px solid var(--c-result);
  border-radius: 14px;
  font-size: 1.2em;
}

/* The tempting wrong move ("1 − 5"), crossed out in red chalk once written. */
.trap {
  position: relative;
  display: inline-block;
  padding: 0 0.2em;
}

.trap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -0.1em;
  left: -0.1em;
  height: 4px;
  border-radius: 2px;
  background: #ff8b8b;
  transform: rotate(-14deg) scaleX(0);
  transform-origin: left center;
  animation: cross-out 450ms ease-out 900ms forwards;
}

@keyframes cross-out {
  to {
    transform: rotate(-14deg) scaleX(1);
  }
}

/* Count back: 11 ↷ 10 ↷ 9 … each number pops in with the faded marble. */
.note-countback {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  row-gap: 0.4em;
  padding-top: 0.5em;
}

.note-caption {
  margin-right: 0.35em;
  color: var(--chalk-soft);
  font-size: 0.85em;
}

.hop {
  position: relative;
  display: inline-block;
  padding-left: 0.7em;
}

.hop:first-of-type {
  padding-left: 0;
}

.hop-arc {
  position: absolute;
  top: -0.45em;
  left: -0.45em;
  width: 1.3em;
  height: 0.7em;
}

.hop-arc path {
  fill: none;
  stroke: var(--c-take);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.note-countback.is-new .hop {
  animation: hop-in 350ms ease-out backwards;
  animation-delay: calc(var(--i) * 650ms);
}

@keyframes hop-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Number bond: 11 → 10 and 1 */
.bond {
  width: min(200px, 100%);
  height: auto;
  margin-left: 0.4em;
  overflow: visible;
}

.bond-line {
  fill: none;
  stroke: var(--chalk-soft);
  stroke-width: 3;
  stroke-linecap: round;
}

.note-bond.is-new .bond-line {
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: draw-line 700ms ease-out 250ms forwards;
}

@keyframes draw-line {
  to {
    stroke-dashoffset: 0;
  }
}

.bond-node {
  fill: rgba(255, 255, 255, 0.05);
  stroke: var(--chalk);
  stroke-width: 3;
}

.bond-node.t-tens {
  stroke: var(--c-tens);
}

.bond-node.t-ones {
  stroke: var(--c-ones);
}

.bond-node.is-blank {
  stroke-dasharray: 6 5;
}

.bond-node.is-active {
  animation: node-blink 1.2s ease-in-out infinite;
}

@keyframes node-blink {
  50% {
    fill: rgba(255, 224, 138, 0.3);
  }
}

.bond text {
  font-family: var(--font-chalk);
  font-size: 26px;
  text-anchor: middle;
  fill: var(--chalk);
}

.bond text.t-tens {
  fill: var(--c-tens);
}

.bond text.t-ones {
  fill: var(--c-ones);
}

/* ---------- overlay & confetti ---------- */

.board-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(14, 30, 26, 0.82);
}

.overlay-card {
  max-width: 540px;
  text-align: center;
}

.overlay-card h2 {
  margin: 0 0 6px;
  font-family: var(--font-chalk);
  font-size: clamp(1.7rem, 4.4vw, 2.6rem);
  font-weight: 400;
  line-height: 1.2;
}

.overlay-card p {
  margin: 0 0 18px;
  color: var(--chalk-soft);
  font-size: 1.15rem;
}

.overlay-stars {
  justify-content: center;
  margin: 6px 0 10px;
}

.overlay-stars .star {
  width: 46px;
  height: 46px;
  color: rgba(255, 255, 255, 0.18);
}

.overlay-stars .star.is-on {
  color: var(--star);
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.confetti {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  left: var(--x);
  width: 10px;
  height: 16px;
  border-radius: 3px;
  opacity: 0;
  animation: confetti-fall var(--fall) cubic-bezier(0.2, 0.6, 0.4, 1) var(--delay) forwards;
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg);
  }

  100% {
    opacity: 0.9;
    transform: translate(var(--drift), 720px) rotate(var(--spin));
  }
}

/* ---------- narrator ---------- */

.narrator {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 18px 0 8px;
}

.speaker {
  flex: none;
  width: 72px;
  height: 72px;
  transform-origin: 50% 100%;
}

.speaker.is-talking {
  animation: owl-talk 520ms ease-in-out infinite alternate;
}

@keyframes owl-talk {
  from {
    transform: rotate(-3deg);
  }

  to {
    transform: rotate(3deg) translateY(-3px);
  }
}

.bubble {
  position: relative;
  flex: 1;
  min-height: 66px;
  margin: 0;
  padding: 12px 18px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 4px 0 var(--line);
  font-size: clamp(1.05rem, 2.2vw, 1.3rem);
  font-weight: 600;
  line-height: 1.35;
}

.bubble::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -11px;
  width: 18px;
  height: 18px;
  border-bottom: 2px solid var(--line);
  border-left: 2px solid var(--line);
  background: var(--surface);
  transform: translateY(-50%) rotate(45deg);
}

.voice-note {
  margin: 0 0 8px 86px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .speaker {
    width: 56px;
    height: 56px;
  }

  .voice-note {
    margin-left: 0;
  }
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.dots {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 4px;
  min-width: 160px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dots button {
  width: 22px;
  height: 22px;
  padding: 4px;
  border: 0;
  border-radius: 50%;
  background: var(--line);
  background-clip: content-box;
  cursor: pointer;
  transition: transform 150ms ease;
}

.dots button.is-done {
  background-color: var(--brand);
  opacity: 0.5;
}

.dots button.is-current {
  background-color: var(--brand);
  transform: scale(1.3);
}

.btn-toggle[aria-pressed="true"] {
  --btn-bg: var(--sky);
  --btn-edge: var(--sky-deep);
  --btn-ink: #fff;
}

.btn-next.is-ready {
  animation: nudge 1.3s ease-in-out infinite;
}

@keyframes nudge {
  50% {
    transform: translateY(-3px);
    box-shadow: 0 8px 0 var(--btn-edge);
  }
}

/* Phones: one row of icon buttons plus a wide "Tiếp". */
@media (max-width: 640px) {
  .explain-controls {
    position: relative;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 40px;
  }

  .explain-controls .dots {
    position: absolute;
    top: -30px;
    right: 0;
    left: 0;
    min-width: 0;
  }

  .explain-controls .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .explain-controls .btn:not(.btn-next) {
    width: 52px;
    flex: none;
    padding: 0;
  }

  .btn-next {
    flex: 1;
    white-space: nowrap;
  }
}

.solver-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "pad hint"
    "cont cont";
}

.round-dots {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.round-dot {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 800;
}

.round-dot.is-current {
  border-color: var(--brand);
  color: var(--brand-deep);
  box-shadow: 0 0 0 4px rgba(255, 138, 61, 0.2);
}

.round-dot.is-done {
  border-color: var(--good);
  background: var(--good);
  color: #fff;
}

.round-dot.is-star {
  border-color: var(--star);
  background: #fff6d6;
}

.round-dot .star {
  width: 26px;
  height: 26px;
}

.number-pad {
  grid-area: pad;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
}

.number-pad .digit {
  min-height: 64px;
  padding: 0;
  font-size: 1.9rem;
  font-weight: 800;
}

.digit.is-pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--btn-edge);
}

.btn-hint {
  grid-area: hint;
  min-height: 64px;
}

.btn-continue {
  grid-area: cont;
  min-height: 64px;
  font-size: 1.3rem;
}

/* Phones: hint gets its own short row so the 2-row number pad stays in view. */
@media (max-width: 760px) {
  .solver-controls {
    grid-template-areas:
      "hint hint"
      "pad pad"
      "cont cont";
  }

  .solver-controls .btn-hint {
    justify-self: end;
    min-height: 48px;
  }

  .round-dots {
    gap: 6px;
  }

  .round-dot {
    width: 36px;
    height: 36px;
  }

  .number-pad {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .number-pad .digit {
    min-height: 54px;
  }
}

@media (max-width: 640px) {
  .narrator {
    gap: 10px;
    margin: 12px 0 6px;
  }

  .bubble {
    min-height: 56px;
    padding: 10px 14px;
    font-size: 1rem;
  }

  .tabs {
    margin-bottom: 10px;
  }
}

/* ---------- marble game ("Tự chơi") ---------- */

.game-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "dots hint"
    "main main"
    "custom custom";
  gap: 10px;
}

.game-controls .round-dots {
  grid-area: dots;
  flex-wrap: wrap;
}

/* Custom rounds can have up to 10 levels. */
.round-dots.is-long {
  gap: 4px;
}

.round-dots.is-long .round-dot {
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
}

.round-dots.is-long .round-dot .star {
  width: 20px;
  height: 20px;
}

/* Parent-facing, so deliberately quieter than the game buttons. */
.custom-open {
  grid-area: custom;
  justify-self: center;
  min-height: 44px;
  padding: 6px 12px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.game-controls .btn-hint {
  grid-area: hint;
  min-height: 48px;
}

.game-actions,
.game-choices,
.game-controls .btn-continue {
  grid-area: main;
}

.game-actions {
  display: flex;
  gap: 10px;
}

.game-actions .btn {
  flex: 1;
  min-height: 68px;
  padding: 0.3em 0.6em;
  font-size: clamp(1.05rem, 2.6vw, 1.35rem);
  white-space: nowrap;
}

.btn.is-shaking {
  animation: shake 420ms ease;
}

.game-choices,
.explain-choices {
  display: flex;
  justify-content: center;
  gap: clamp(16px, 5vw, 40px);
  padding: 4px 0 8px;
}

.choice {
  width: 84px;
  height: 84px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #b5ecff 35%, #2f8fd6);
  box-shadow: 0 6px 0 #1f6ca8, inset 0 -6px 12px rgba(0, 0, 0, 0.15);
  color: #10304a;
  font-family: var(--font-ui);
  font-size: 2.4rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.choice:hover:not(:disabled) {
  transform: translateY(-3px);
}

.choice:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #1f6ca8;
}

.choice.is-wrong {
  background: radial-gradient(circle at 35% 30%, #ffffff, #d9d9d9 40%, #9a9a9a);
  box-shadow: 0 6px 0 #7d7d7d;
  color: #5a5a5a;
  opacity: 0.6;
  cursor: not-allowed;
  animation: shake 420ms ease;
}

@media (max-width: 640px) {
  .choice {
    width: 72px;
    height: 72px;
    font-size: 2rem;
  }

  .game-actions .btn {
    min-height: 60px;
  }
}

/* ---------- "Tự ra đề" dialog ---------- */

.custom-dialog {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.custom-dialog::backdrop {
  background: rgba(10, 14, 30, 0.55);
}

.custom-dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: clamp(18px, 4vw, 28px);
}

.custom-dialog h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.2;
}

.custom-help {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.custom-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  margin: 0;
  padding: 2px;
  overflow-y: auto;
  list-style: none;
  counter-reset: row;
}

.custom-row {
  display: grid;
  grid-template-columns: 2em 72px 1.6em 72px 44px;
  justify-content: start;
  align-items: center;
  gap: 2px 8px;
  counter-increment: row;
}

.custom-row::before {
  content: counter(row) ".";
  color: var(--ink-soft);
  font-weight: 800;
}

.custom-input {
  width: 72px;
  height: 52px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}

.custom-input:focus {
  border-color: var(--sky);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 167, 255, 0.3);
}

.custom-row.is-valid .custom-input {
  border-color: var(--good);
}

.custom-row.is-invalid .custom-input {
  border-color: var(--bad);
}

.custom-op {
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
}

.custom-remove {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.1rem;
  cursor: pointer;
}

.custom-remove:hover {
  background: var(--bg-accent);
}

.custom-note {
  grid-column: 2 / -1;
  font-size: 0.9rem;
  font-weight: 600;
}

.custom-note:empty {
  display: none;
}

.custom-row.is-valid .custom-note {
  color: var(--good);
}

.custom-row.is-invalid .custom-note {
  color: var(--bad);
}

.custom-add {
  align-self: flex-start;
}

.custom-error {
  min-height: 1.4em;
  margin: 0;
  color: var(--bad);
  font-weight: 700;
}

.custom-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 480px) {
  .custom-actions .btn {
    flex: 1 1 auto;
  }
}

/* ---------- worksheet ("Làm bài tập"): the textbook exercise on the board ---------- */

.board.is-worksheet {
  grid-template-columns: 1fr;
}

.board.is-worksheet .board-art,
.board.is-worksheet .board-notes {
  display: none;
}

.worksheet {
  padding: clamp(6px, 2vw, 22px) clamp(6px, 5vw, 64px);
  color: var(--chalk);
  font-family: var(--font-chalk);
  font-size: clamp(28px, 4.2vw, 46px);
  line-height: 1.3;
}

.ws-title {
  margin: 0 0 0.3em;
}

.ws-letter {
  margin-right: 0.25em;
}

.ws-steps {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  margin: 0;
  padding-left: 1.4em;
  list-style: none;
}

.ws-steps li,
.ws-final {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25em;
}

.ws-steps li {
  position: relative;
}

.ws-steps li::before {
  content: "•";
  position: absolute;
  left: -0.9em;
}

.ws-final {
  margin: 0.5em 0 0 1.4em;
}

/* A box to write in, like the squares in the exercise book. */
.ws-box {
  display: inline-grid;
  place-items: center;
  width: 1.5em;
  height: 1.35em;
  padding: 0;
  border: 3px solid rgba(244, 241, 232, 0.75);
  border-radius: 0.22em;
  background: rgba(255, 255, 255, 0.04);
  color: var(--chalk);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ws-box:disabled {
  opacity: 1;
  cursor: default;
}

.ws-box.is-active {
  border-color: var(--c-tag);
  background: rgba(255, 224, 138, 0.16);
  box-shadow: 0 0 0 4px rgba(255, 224, 138, 0.25);
  animation: blank-blink 1.2s ease-in-out infinite;
}

.ws-box.is-right {
  border-color: var(--c-result);
  color: var(--c-result);
}

.ws-box.is-wrong {
  border-color: #ff8b8b;
  color: #ff8b8b;
  text-decoration: line-through;
  text-decoration-thickness: 3px;
}

.ws-box.is-shaking {
  animation: shake 420ms ease;
}

/* The right number, written beside a wrong box like a teacher's correction. */
.ws-fix {
  display: inline-block;
  color: var(--c-result);
  font-size: 0.85em;
  transform: rotate(-8deg) translateY(-0.35em);
}

.exercise-controls {
  display: grid;
  gap: 10px;
}

.exercise-controls .round-dots {
  justify-content: center;
  flex-wrap: wrap;
}

.round-dot.is-miss {
  border-color: var(--bad);
  color: var(--bad);
}

.exercise-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.exercise-pad {
  grid-area: auto; /* .number-pad is placed for the guided layout */
  grid-template-columns: repeat(11, minmax(0, 1fr));
}

.exercise-controls .btn-continue,
.exercise-controls .custom-open {
  grid-area: auto;
}

.exercise-controls .round-dot.is-star {
  color: #8a6400;
}

.exercise-submit {
  min-height: 64px;
  font-size: 1.25rem;
}

.exercise-submit.is-ready {
  animation: nudge 1.3s ease-in-out infinite;
}

@media (max-width: 760px) {
  .exercise-inputs {
    grid-template-columns: 1fr;
  }

  .exercise-pad {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
