:root {
  --navy: #112240;
  --navy-2: #1d3557;
  --teal: #0f8f8b;
  --teal-dark: #08736f;
  --teal-pale: #e9f8f6;
  --yellow: #f7c948;
  --yellow-pale: #fff7d6;
  --ink: #14213d;
  --muted: #596b85;
  --line: #d8e1ed;
  --paper: #ffffff;
  --canvas: #f3f6fa;
  --green: #087f5b;
  --green-pale: #e8f7f0;
  --red: #c92a3d;
  --red-pale: #fff0f1;
  --shadow: 0 14px 34px rgba(17, 34, 64, .08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.55;
}

button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 76px;
  padding: 12px clamp(18px, 3vw, 44px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: white;
  background: var(--navy);
  border-bottom: 4px solid var(--yellow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--navy);
  background: var(--yellow);
  font: 800 29px/1 Georgia, serif;
}

.brand strong { display: block; font-size: 19px; letter-spacing: .01em; }
.brand small, .score-chip small { display: block; color: #c8d5e8; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }

.score-chip {
  min-width: 104px;
  padding: 7px 14px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 12px;
  background: rgba(255,255,255,.07);
}

.score-chip span { display: block; font-weight: 800; font-size: 18px; }

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 26px clamp(16px, 3vw, 42px) 56px;
  display: grid;
  grid-template-columns: 285px minmax(0, 1fr);
  gap: 28px;
}

.sidebar { position: sticky; top: 22px; align-self: start; }
.eyebrow { margin: 0 0 10px; color: var(--teal-dark); font-size: 12px; font-weight: 800; letter-spacing: .13em; }

#checkpointNav { display: grid; gap: 9px; }

.checkpoint-button {
  width: 100%;
  min-height: 66px;
  padding: 11px;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 11px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--paper);
}

.checkpoint-button:hover { border-color: var(--teal); transform: translateY(-1px); }
.checkpoint-button.active { color: white; border-color: var(--navy); background: var(--navy); box-shadow: var(--shadow); }

.checkpoint-number {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: white;
  background: var(--teal);
  font-weight: 800;
}

.checkpoint-button.active .checkpoint-number { color: var(--navy); background: var(--yellow); }
.checkpoint-label strong { display: block; font-size: 15px; line-height: 1.25; }
.checkpoint-label small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.checkpoint-button.active .checkpoint-label small { color: #c8d5e8; }
.checkpoint-status { font-size: 12px; font-weight: 800; }

.rule-card {
  margin-top: 19px;
  padding: 17px;
  border: 1px solid #ead88b;
  border-radius: 14px;
  background: var(--yellow-pale);
}
.rule-card p:not(.eyebrow) { margin: 6px 0; font-size: 14px; line-height: 1.45; }

main { min-width: 0; }

.lesson-head {
  margin-bottom: 20px;
  padding: clamp(24px, 4vw, 42px);
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  color: white;
  background: linear-gradient(120deg, var(--teal-dark), var(--teal));
  box-shadow: var(--shadow);
}

.lesson-head::after {
  content: "÷";
  position: absolute;
  right: 30px;
  top: -35px;
  color: rgba(255,255,255,.10);
  font: 800 190px/1 Georgia, serif;
}

.lesson-head .eyebrow { color: var(--yellow); }
.lesson-head h1 { margin: 0; max-width: 780px; font: 800 clamp(30px, 4.5vw, 52px)/1.08 Georgia, serif; }
.lesson-head p { max-width: 760px; margin: 14px 0 0; color: #e5fbf9; }

.section-intro {
  margin: 0 0 18px;
  padding: 18px 22px;
  border-left: 5px solid var(--yellow);
  border-radius: 6px 14px 14px 6px;
  background: var(--paper);
}
.section-intro strong { color: var(--teal-dark); }

.demo-list { display: grid; gap: 18px; }

.demo-card, .question-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.demo-card.done { border-color: #94d4c4; }

.demo-top {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--teal-pale), white);
}

.demo-title { display: flex; align-items: center; gap: 13px; }
.demo-number { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 11px; color: white; background: var(--teal); font-weight: 800; }
.demo-title .eyebrow { margin-bottom: 2px; }
.demo-title h2 { margin: 0; font-size: 21px; }
.demo-story { padding: 20px 24px 5px; color: var(--muted); }

.equation-banner {
  margin: 14px 24px 18px;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px solid #e7d178;
  border-radius: 13px;
  background: var(--yellow-pale);
  font-weight: 800;
  font-size: clamp(20px, 3vw, 27px);
}

.math { font-family: "Trebuchet MS", ui-rounded, sans-serif; font-weight: 800; letter-spacing: .04em; }

.demo-body { padding: 0 24px 24px; }

.move-panel {
  padding: 17px;
  text-align: center;
  border: 1px dashed #7abeb8;
  border-radius: 13px;
  background: #f8fffe;
}
.move-panel p { margin: 4px 0 10px; }
.arrow-track { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; font-size: 22px; }
.move-count { display: inline-grid; place-items: center; min-height: 34px; padding: 4px 11px; border-radius: 9px; color: white; background: var(--teal); font-weight: 800; font-size: 15px; letter-spacing: 0; }
.decimal-move-arrow { color: var(--teal-dark); animation: nudge-right .9s ease-in-out both; }

.calculation-grid {
  margin-top: 16px;
  display: block;
}

.calculation-panel {
  min-height: 300px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background-color: #fbfcff;
  background-image: linear-gradient(#e9eef6 1px, transparent 1px), linear-gradient(90deg, #e9eef6 1px, transparent 1px);
  background-size: 28px 28px;
}
.calculation-panel .eyebrow { text-align: center; }

.long-division {
  --cell: 1.48em;
  width: max-content;
  min-width: 240px;
  min-height: 205px;
  margin: 20px auto 0;
  display: grid;
  grid-template-columns: minmax(2.8em, auto) 4px repeat(var(--places), var(--cell));
  grid-template-rows: 1.55em 3px 1.7em 1.7em 2px 1.7em;
  align-items: center;
  justify-items: center;
  color: var(--navy);
  font: 800 clamp(28px, 4vw, 38px)/1 "Courier New", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}
.two-digit-division {
  min-height: 340px;
  grid-template-rows: 1.55em 3px 1.7em 1.7em 2px 1.7em 1.7em 2px 1.7em;
}
.ld-top-line { width: 100%; height: 3px; align-self: end; background: var(--navy); }
.ld-side-line { width: 3px; height: 100%; justify-self: start; background: var(--navy); }
.ld-divisor { padding-right: .25em; justify-self: end; }
.ld-digit { width: var(--cell); display: grid; place-items: center; }
.ld-quotient-digit { color: var(--teal-dark); align-self: end; }
.ld-dividend-digit { align-self: center; }
.ld-product-digit { color: var(--muted); }
.ld-remainder-digit { color: var(--teal-dark); }
.ld-minus { justify-self: center; color: var(--muted); }
.ld-subtract-line { width: 100%; height: 2px; align-self: start; background: #64748b; }
.reveal-number { animation: reveal-number .28s ease-out both; }
.column-caption { min-height: 31px; margin: -2px 0 0; text-align: center; color: var(--muted); font-weight: 650; }

.ld-restored-remainder {
  position: relative;
  justify-self: end;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--cell);
  align-items: center;
  justify-items: center;
  color: var(--teal-dark);
}
.ld-temporary-remainder {
  position: relative;
  justify-self: end;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--cell);
  align-items: center;
  justify-items: center;
  color: var(--teal-dark);
}
.hidden-decimal-point {
  position: absolute;
  right: -.08em;
  bottom: .02em;
  color: var(--red);
  animation: pulse-decimal 1s ease-in-out infinite alternate;
}
.restored-leading-zero { opacity: 0; animation: reveal-leading-zero .25s ease-out 1.35s forwards; }
.unused-trailing-zero { animation: hide-unused-zero .25s ease-out 1.55s forwards; }
.moving-decimal-point {
  position: absolute;
  right: -.08em;
  bottom: .02em;
  color: var(--red);
  font-family: "Courier New", ui-monospace, monospace;
  animation-duration: 1.45s;
  animation-timing-function: ease-in-out;
  animation-fill-mode: forwards;
}
.ld-restored-remainder.shift-1 .moving-decimal-point { animation-name: jump-decimal-left-one; }
.ld-restored-remainder.shift-2 .moving-decimal-point { animation-name: jump-decimal-left-two; }

.ld-quotient-blank { width: calc(var(--cell) * 1.8); align-self: end; justify-self: end; }
.ld-remainder-blank { width: calc(var(--cell) * 1.8); justify-self: end; }

.column-digit-input {
  width: calc(var(--cell) - .12em);
  min-width: 0;
  height: 1.34em;
  padding: 0;
  align-self: center;
  justify-self: center;
  border: 2px dashed #91a3bd;
  border-radius: .22em;
  color: var(--navy);
  background: rgba(255,255,255,.94);
  font: inherit;
  font-size: .82em;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.column-digit-input.correct { border-style: solid; border-color: var(--green); background: var(--green-pale); }
.column-digit-input.incorrect { border-style: solid; border-color: var(--red); background: var(--red-pale); }
.guided-column-division { margin-top: 10px; }
.guided-column-division .ld-minus { font-size: .9em; }
.guided-remainder-action { margin-top: 10px; display: grid; justify-items: center; gap: 8px; }
.work-feedback { min-height: 26px; margin: 0; text-align: center; font-weight: 700; }
.work-feedback.error { color: var(--red); }
.work-feedback.success { color: var(--green); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes reveal-number {
  from { opacity: 0; transform: translateY(-7px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes nudge-right {
  from { opacity: .25; transform: translateX(-5px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes jump-decimal-left-one {
  0% { transform: translate(0, 0); }
  48% { transform: translate(calc(var(--cell) * -.5), -.48em); }
  100% { transform: translate(calc(var(--cell) * -1), 0); }
}

@keyframes jump-decimal-left-two {
  0% { transform: translate(0, 0); }
  24% { transform: translate(calc(var(--cell) * -.5), -.48em); }
  46% { transform: translate(calc(var(--cell) * -1), 0); }
  70% { transform: translate(calc(var(--cell) * -1.5), -.48em); }
  100% { transform: translate(calc(var(--cell) * -2), 0); }
}

@keyframes reveal-leading-zero {
  from { opacity: 0; transform: translateX(.3em); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes hide-unused-zero {
  to { opacity: 0; }
}

@keyframes pulse-decimal {
  from { opacity: .45; transform: scale(.85); }
  to { opacity: 1; transform: scale(1.18); }
}

.remainder-return {
  margin-top: 16px;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  border: 1px solid #a8dccf;
  border-radius: 14px;
  background: var(--green-pale);
}
.remainder-return p { margin: 4px 0; }
.final-statements { padding: 13px 16px; border-radius: 11px; background: white; font-weight: 700; }

.demo-actions { margin-top: 16px; display: flex; justify-content: center; }
.primary-button, .secondary-button, .nav-button {
  min-height: 48px;
  padding: 11px 20px;
  border-radius: 11px;
  font-weight: 800;
}
.primary-button { color: white; border: 1px solid var(--navy); background: var(--navy); }
.primary-button:hover { background: var(--navy-2); }
.secondary-button { color: var(--navy); border: 1px solid #b9c8dc; background: white; }
.secondary-button:hover { border-color: var(--teal); }
.nav-button { color: var(--teal-dark); border: 0; background: transparent; }
.nav-button:hover { background: var(--teal-pale); }
.primary-button:focus-visible, .secondary-button:focus-visible, .nav-button:focus-visible, .checkpoint-button:focus-visible, .question-tab:focus-visible, input:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.takeaway {
  margin-top: 20px;
  padding: 22px;
  border-radius: 16px;
  color: var(--navy);
  background: var(--yellow-pale);
  border: 1px solid #ead270;
}
.takeaway h3 { margin: 0 0 7px; font-size: 20px; }
.takeaway p { margin: 5px 0; }

.question-tabs { margin: 0 0 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.question-tab { width: 47px; height: 47px; border: 1px solid #b8c7dc; border-radius: 12px; color: var(--navy); background: white; font-weight: 800; }
.question-tab.active { color: white; border-color: var(--navy); background: var(--navy); }
.question-tab.correct { color: white; border-color: var(--green); background: var(--green); }

.question-head {
  padding: 17px 24px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-top: 5px solid var(--teal);
  border-bottom: 1px solid var(--line);
}
.question-head p { margin: 0; color: var(--teal-dark); font-size: 13px; font-weight: 800; letter-spacing: .1em; }

.story-panel { padding: clamp(24px, 4vw, 38px); }
.story-panel h2 { margin: 0 0 8px; color: var(--navy); font: 700 clamp(23px, 3vw, 32px)/1.3 Georgia, serif; }
.story-panel p { margin: 0; color: var(--muted); }

.guide-strip {
  margin: 0 clamp(22px, 4vw, 38px) 25px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.guide-step { padding: 14px; border-radius: 12px; background: var(--teal-pale); }
.guide-step strong { display: block; color: var(--teal-dark); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.guide-step span { display: block; margin-top: 5px; font-weight: 700; }

.guided-work {
  margin: 0 clamp(22px, 4vw, 38px) 28px;
  padding: 20px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 14px;
  background-color: #fafcff;
  background-image: linear-gradient(#e9eef6 1px, transparent 1px), linear-gradient(90deg, #e9eef6 1px, transparent 1px);
  background-size: 28px 28px;
}
.guided-work p { margin: 4px 0; text-align: center; }
.guided-instruction { color: var(--muted); font-weight: 650; }
.blank-division .ld-quotient, .blank-division .ld-remainder { color: #8b9ab0; }
.blank-box { display: inline-block; min-width: 66px; height: 34px; vertical-align: middle; border: 2px dashed #9baac0; border-radius: 7px; background: rgba(255,255,255,.75); }

.answer-area { padding: 0 clamp(22px, 4vw, 38px) 30px; }
.answer-area h3 { margin: 0 0 12px; font-size: 19px; }
.sentence-box { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: #f9fbfd; }
.answer-sentence { margin: 9px 0; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.answer-input {
  height: 48px;
  padding: 8px 10px;
  border: 1.5px solid #a9b9cd;
  border-bottom: 3px solid var(--teal);
  border-radius: 9px;
  color: var(--navy);
  background: white;
  font-weight: 800;
  text-align: center;
}
.number-input { width: 100px; }
.unit-input { width: 140px; }
.answer-input.correct { border-color: var(--green); background: var(--green-pale); }
.answer-input.incorrect { border-color: var(--red); background: var(--red-pale); }

.question-actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 10px; }
.feedback { min-height: 0; margin-top: 15px; padding: 14px 16px; border-radius: 11px; font-weight: 650; }
.feedback:empty { display: none; }
.feedback.success { color: #076044; background: var(--green-pale); }
.feedback.error { color: #a51d30; background: var(--red-pale); }
.feedback.hint { color: #715b00; background: var(--yellow-pale); }

.bottom-nav {
  margin-top: 20px;
  padding-top: 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}
.bottom-nav .disabled { visibility: hidden; }

.completion {
  padding: 35px;
  text-align: center;
  border: 1px solid #9ad7c7;
  border-radius: 18px;
  background: var(--green-pale);
}
.completion h2 { margin: 0 0 8px; font: 800 31px/1.15 Georgia, serif; }
.completion p { margin: 5px 0; }

@media (max-width: 930px) {
  .app-shell { grid-template-columns: 1fr; padding-top: 18px; }
  .sidebar { position: static; }
  #checkpointNav { grid-template-columns: repeat(3, minmax(180px, 1fr)); overflow-x: auto; padding-bottom: 6px; }
  .rule-card { display: none; }
  .calculation-grid, .guided-work { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
  body { font-size: 16px; }
  .topbar { padding: 10px 14px; }
  .brand small { display: none; }
  .brand strong { font-size: 16px; }
  .brand-mark { width: 40px; height: 40px; }
  .score-chip { min-width: 84px; padding: 6px 9px; }
  .app-shell { padding: 14px 12px 40px; gap: 14px; }
  #checkpointNav { grid-template-columns: repeat(3, 210px); }
  .checkpoint-button { min-height: 59px; }
  .lesson-head { padding: 25px 21px; }
  .lesson-head h1 { font-size: 32px; }
  .demo-top { align-items: flex-start; padding: 15px; }
  .demo-top .status-text { display: none; }
  .demo-story, .demo-body { padding-left: 16px; padding-right: 16px; }
  .equation-banner { margin-left: 16px; margin-right: 16px; }
  .remainder-return { grid-template-columns: 1fr; }
  .question-head, .story-panel, .answer-area { padding-left: 18px; padding-right: 18px; }
  .guide-strip { margin-left: 18px; margin-right: 18px; grid-template-columns: 1fr; }
  .guided-work { margin-left: 18px; margin-right: 18px; }
  .answer-sentence { align-items: flex-end; }
  .number-input { width: 82px; }
  .unit-input { width: 120px; }
  .question-actions { flex-direction: column-reverse; }
  .question-actions button { width: 100%; }
  .bottom-nav { flex-direction: column; }
  .bottom-nav button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
