:root {
  --ink: #10213f;
  --muted: #5e6f8c;
  --paper: #f7f9fd;
  --white: #ffffff;
  --teal: #087b78;
  --teal-dark: #075c5a;
  --teal-soft: #dff5f1;
  --navy: #132342;
  --yellow: #ffd84d;
  --yellow-soft: #fff6c9;
  --blue-soft: #eaf1ff;
  --red: #c83d51;
  --red-soft: #fff0f2;
  --green: #168558;
  --green-soft: #e6f7ef;
  --line: #d8e1ef;
  --shadow: 0 18px 55px rgba(16, 33, 63, 0.1);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(rgba(19, 35, 66, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 35, 66, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button, input { font: inherit; }

button { cursor: pointer; }

.skip-link {
  position: fixed;
  left: 16px;
  top: -80px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--navy);
  color: white;
}

.skip-link:focus { top: 12px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  min-height: 92px;
  padding: 14px clamp(20px, 4vw, 58px);
  border-bottom: 1px solid rgba(216, 225, 239, 0.9);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 15px; min-width: 0; }

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 66px;
  min-height: 61px;
  place-content: center;
  padding: 6px 10px;
  border-radius: 16px;
  background: var(--teal);
  color: white;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
  box-shadow: 0 7px 0 var(--teal-dark);
}

.brand-mark i { display: block; width: 38px; height: 2px; margin: 4px 0; background: var(--yellow); }

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 850;
  letter-spacing: 0.12em;
}

h1, h2, h3, p { margin-top: 0; }

h1 { margin-bottom: 0; font-size: clamp(1.08rem, 2vw, 1.55rem); line-height: 1.2; }

.progress-cluster { width: min(360px, 35vw); }

.progress-copy { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; color: var(--muted); font-size: 0.875rem; }
.progress-copy strong { color: var(--teal-dark); }

.progress-track { height: 9px; overflow: hidden; border-radius: 999px; background: #e7edf6; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #16aaa3); transition: width 350ms ease; }

.quiet-button { float: right; margin-top: 8px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 0.8rem; text-decoration: underline; text-underline-offset: 3px; }

.app-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 92px); }

.checkpoint-panel {
  padding: 28px 22px 42px clamp(20px, 3vw, 42px);
  border-right: 1px solid var(--line);
  background: rgba(239, 244, 251, 0.82);
}

.panel-heading { margin-bottom: 16px; }
.panel-heading span { display: block; font-weight: 850; }
.panel-heading small { color: var(--muted); }

.checkpoint-nav { display: grid; gap: 9px; }

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

.checkpoint-button:hover { background: white; border-color: var(--line); }
.checkpoint-button.active { background: var(--navy); color: white; box-shadow: 0 9px 22px rgba(19,35,66,.18); }

.checkpoint-number {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 11px;
  background: white;
  color: var(--teal-dark);
  font-weight: 900;
  box-shadow: inset 0 0 0 1px var(--line);
}

.checkpoint-button.active .checkpoint-number { background: var(--yellow); color: var(--navy); box-shadow: none; }
.checkpoint-name { min-width: 0; font-size: .9rem; font-weight: 760; line-height: 1.25; }
.checkpoint-status { color: var(--green); font-weight: 900; }
.checkpoint-button.active .checkpoint-status { color: var(--yellow); }

.lesson { width: min(1040px, 100%); margin: 0 auto; padding: clamp(28px, 4vw, 54px); }

.lesson-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 26px; margin-bottom: 24px; }
.checkpoint-label { margin-bottom: 5px; color: var(--teal); font-size: .8rem; font-weight: 850; letter-spacing: .1em; }
.lesson-heading h2 { margin-bottom: 8px; font-size: clamp(1.75rem, 3.2vw, 2.7rem); line-height: 1.08; letter-spacing: -0.035em; }
.objective { max-width: 720px; margin-bottom: 0; color: var(--muted); font-size: 1.02rem; }

.rule-chip {
  flex: 0 0 min(270px, 32%);
  padding: 13px 15px;
  border: 1px solid #efd358;
  border-radius: 14px;
  background: var(--yellow-soft);
  color: #594811;
  font-size: .88rem;
  font-weight: 720;
}

.phase-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }

.phase-tab {
  position: relative;
  min-height: 55px;
  padding: 10px 13px 10px 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  color: var(--muted);
  text-align: left;
  font-weight: 760;
}

.phase-tab::before {
  position: absolute;
  left: 12px;
  top: 50%;
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  background: #e8eef7;
  content: attr(data-step);
  transform: translateY(-50%);
  font-size: .8rem;
}

.phase-tab.active { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.phase-tab.active::before { background: var(--teal); color: white; }
.phase-tab:disabled { cursor: not-allowed; opacity: .52; }

.stage-card {
  min-height: 500px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 6px solid var(--teal);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
}

.stage-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 24px clamp(20px, 4vw, 38px); border-bottom: 1px solid var(--line); }
.stage-kicker { margin-bottom: 3px; color: var(--teal); font-size: .78rem; font-weight: 850; letter-spacing: .1em; }
.stage-header h3 { margin-bottom: 0; font-size: clamp(1.25rem, 2vw, 1.65rem); }
.stage-badge { flex: 0 0 auto; padding: 7px 11px; border-radius: 999px; background: var(--blue-soft); color: #335b9f; font-size: .8rem; font-weight: 800; }

.stage-body { padding: clamp(24px, 4vw, 42px); }
.prompt { margin-bottom: 22px; color: var(--muted); font-size: 1.02rem; }

.math-board {
  display: grid;
  min-height: 112px;
  place-items: center;
  margin-bottom: 24px;
  padding: 22px;
  border: 1px solid #d9e3f2;
  border-radius: 18px;
  background:
    linear-gradient(rgba(19,35,66,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19,35,66,.05) 1px, transparent 1px),
    #f8fbff;
  background-size: 28px 28px;
  font-family: "Trebuchet MS", ui-sans-serif, sans-serif;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  font-weight: 800;
}

.math-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; }
.equals { color: var(--teal); }
.highlight-number { color: var(--teal); }

.fraction { display: inline-grid; grid-template-rows: auto 2px auto; align-items: center; min-width: 1.7em; vertical-align: middle; text-align: center; line-height: 1.08; }
.fraction .bar { width: 100%; height: 2px; background: currentColor; }
.fraction .top, .fraction .bottom { padding: 0 .18em; }
.mixed { display: inline-flex; align-items: center; gap: .16em; }

.demo-steps { display: grid; gap: 11px; margin: 0 0 24px; padding: 0; list-style: none; }
.demo-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  animation: rise .28s ease both;
}
.demo-step-number { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: var(--teal-soft); color: var(--teal-dark); font-weight: 900; }
.demo-step p { margin: 0; }
.demo-step strong { color: var(--teal-dark); }

.place-strip { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.place-cell { min-width: 78px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: white; text-align: center; }
.place-cell small { display: block; color: var(--muted); font-size: .7rem; }
.place-cell strong { display: block; color: var(--teal-dark); font-size: 1.25rem; }

.work-lines { display: grid; gap: 16px; margin-bottom: 22px; }
.work-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; min-height: 62px; padding: 13px; border-radius: 14px; background: #f6f8fc; font-size: clamp(1.25rem, 3vw, 1.75rem); font-weight: 800; }

.answer-input {
  width: 84px;
  height: 50px;
  padding: 7px 9px;
  border: 2px solid #9fb1cb;
  border-radius: 10px;
  background: white;
  color: var(--ink);
  font-weight: 850;
  text-align: center;
  outline: none;
}
.answer-input.small { width: 64px; }
.answer-input.wide { width: 116px; }
.answer-input:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(8,123,120,.14); }
.answer-input.correct { border-color: var(--green); background: var(--green-soft); }
.answer-input.incorrect { border-color: var(--red); background: var(--red-soft); }

.hint-box, .feedback-box, .rule-summary { margin: 18px 0; padding: 15px 17px; border-radius: 13px; }
.hint-box { border-left: 4px solid #dbb516; background: var(--yellow-soft); color: #5f4d12; }
.feedback-box { border-left: 4px solid var(--red); background: var(--red-soft); color: #7a2633; }
.feedback-box.success { border-left-color: var(--green); background: var(--green-soft); color: #105d3f; }
.rule-summary { border: 1px solid #bfe5dd; background: var(--teal-soft); color: var(--teal-dark); }
.hint-box[hidden], .feedback-box[hidden] { display: none; }

.action-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.primary-button, .secondary-button, .danger-button {
  min-height: 48px;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 820;
}
.primary-button { border: 1px solid var(--navy); background: var(--navy); color: white; box-shadow: 0 5px 0 #071126; }
.primary-button:hover { transform: translateY(-1px); }
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #071126; }
.secondary-button { border: 1px solid #b8c6da; background: white; color: var(--ink); }
.danger-button { border: 1px solid var(--red); background: var(--red); color: white; }

.completion-panel { display: grid; place-items: center; padding: 22px; border-radius: 16px; background: var(--green-soft); text-align: center; }
.completion-mark { display: grid; width: 54px; height: 54px; place-items: center; margin-bottom: 10px; border-radius: 50%; background: var(--green); color: white; font-size: 1.65rem; font-weight: 900; }
.completion-panel h3 { margin-bottom: 5px; }
.completion-panel p { margin-bottom: 0; color: #2c6d55; }

.strategy-board { display: grid; gap: 14px; }
.strategy-board .math-line { padding: 9px 14px; border-radius: 12px; background: rgba(255,255,255,.82); }

.type-tag { padding: 5px 9px; border-radius: 999px; font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: .78rem; font-weight: 850; }
.type-tag.terminate { background: var(--green-soft); color: var(--green); }
.type-tag.recur { background: var(--yellow-soft); color: #725a00; }

.recurring-number {
  display: inline-flex;
  align-items: flex-end;
  min-height: 1.8em;
  padding-top: .35em;
  white-space: nowrap;
}

.decimal-whole { align-self: flex-end; }

.digit-column {
  position: relative;
  display: inline-grid;
  min-width: .72em;
  place-items: end center;
  padding-top: .34em;
}

.fixed-dot {
  position: absolute;
  top: .02em;
  left: 50%;
  width: .18em;
  height: .18em;
  border-radius: 50%;
  background: var(--teal);
  transform: translateX(-50%);
}

.recurring-builder {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  grid-template-areas: "instruction instruction" "bank number";
  align-items: center;
  gap: 10px 18px;
  width: min(100%, 480px);
  padding: 15px;
  border: 2px solid transparent;
  border-radius: 15px;
  background: white;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  transition: border-color 180ms ease, background 180ms ease;
}

.recurring-builder.correct { border-color: var(--green); background: var(--green-soft); }
.recurring-builder.incorrect { border-color: var(--red); background: var(--red-soft); }

.dot-instruction { grid-area: instruction; color: var(--muted); font-size: .84rem; font-weight: 650; line-height: 1.35; }

.dot-bank {
  grid-area: bank;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 8px 12px;
  border: 2px dashed #a8b7cb;
  border-radius: 12px;
  background: #f5f8fc;
}

.dot-bank::before { margin-right: 3px; color: var(--muted); content: "Dots"; font-size: .76rem; font-weight: 800; }

.dot-token {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0 0 12px;
  border: 2px solid #c89e00;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--teal-dark);
  cursor: grab;
  font-size: 1.85rem;
  font-weight: 900;
  line-height: 1;
  touch-action: none;
  user-select: none;
}

.dot-token.selected { outline: 4px solid rgba(8,123,120,.2); border-color: var(--teal); }
.dot-token:active { cursor: grabbing; }

.recurring-number.editable { grid-area: number; min-height: 70px; font-family: "Trebuchet MS", ui-sans-serif, sans-serif; font-size: 2rem; font-weight: 850; }
.recurring-number.editable .digit-column { min-width: 44px; padding-top: 34px; }

.dot-slot {
  position: absolute;
  top: 0;
  left: 50%;
  display: grid;
  width: 38px;
  height: 29px;
  place-items: center;
  border: 2px dashed #9eb0c8;
  border-radius: 9px;
  background: #f8fbff;
  transform: translateX(-50%);
}

.dot-slot:focus { outline: 3px solid rgba(8,123,120,.2); border-color: var(--teal); }
.dot-slot.correct { border-color: var(--green); background: #d5f2e4; }
.dot-slot.incorrect { border-color: var(--red); background: #ffe0e5; }
.dot-slot .dot-token { width: 28px; height: 28px; padding-bottom: 11px; border-width: 1px; font-size: 1.45rem; }

.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.05);
  box-shadow: 0 10px 24px rgba(16,33,63,.25);
}

.lesson-footer { display: flex; justify-content: space-between; gap: 20px; padding-top: 24px; }
.text-button { border: 0; background: transparent; color: var(--teal-dark); font-weight: 800; }
.text-button:disabled { cursor: not-allowed; opacity: .35; }

.confirm-dialog { width: min(500px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 20px; box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgba(8, 18, 38, .55); backdrop-filter: blur(3px); }
.confirm-dialog form { padding: 28px; }
.confirm-dialog h2 { margin-bottom: 8px; }
.confirm-dialog p:not(.eyebrow) { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

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

@media (max-width: 900px) {
  .topbar { position: static; align-items: flex-start; }
  .progress-cluster { width: 42%; }
  .app-shell { display: block; }
  .checkpoint-panel { padding: 18px 20px; border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-heading { margin-bottom: 10px; }
  .checkpoint-nav { display: flex; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .checkpoint-button { flex: 0 0 190px; grid-template-columns: 34px 1fr; }
  .checkpoint-status { display: none; }
  .checkpoint-number { width: 34px; height: 34px; }
}

@media (max-width: 650px) {
  .topbar { display: block; padding: 14px 18px 18px; }
  .brand-mark { width: 57px; min-height: 54px; }
  .progress-cluster { width: 100%; margin-top: 18px; }
  .quiet-button { float: none; }
  .lesson { padding: 26px 16px 38px; }
  .lesson-heading { display: block; }
  .rule-chip { width: 100%; margin-top: 16px; }
  .phase-tabs { gap: 6px; }
  .phase-tab { min-height: 64px; padding: 34px 7px 7px; text-align: center; font-size: .77rem; }
  .phase-tab::before { left: 50%; top: 6px; transform: translateX(-50%); width: 23px; height: 23px; }
  .stage-card { min-height: 0; }
  .stage-header { align-items: flex-start; padding: 20px; }
  .stage-badge { display: none; }
  .stage-body { padding: 22px 17px; }
  .math-board { padding: 18px 10px; }
  .work-line { padding: 11px 6px; }
  .answer-input { width: 72px; }
  .answer-input.small { width: 57px; }
  .recurring-builder { grid-template-columns: 1fr; grid-template-areas: "instruction" "bank" "number"; justify-items: center; }
  .dot-bank { width: 100%; justify-content: center; }
  .recurring-number.editable { margin-top: 2px; }
  .action-row { justify-content: stretch; }
  .action-row button { flex: 1 1 150px; }
  .lesson-footer { font-size: .88rem; }
}

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