:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-muted: #f0f0f2;
  --text: #171717;
  --muted: #60616a;
  --line: #d9d9de;
  --accent: #2457d6;
  --accent-soft: #e8eefc;
  --correct: #2457d6;
  --correct-soft: #e8eefc;
  --incorrect: #9a3412;
  --incorrect-soft: #f3ece8;
  --hint: #555862;
  --hint-soft: #eeeef1;
  --complete: #2457d6;
  --complete-soft: #e8eefc;
  --focus: #111111;
  --radius: 8px;
  --font: Helvetica, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517;
    --surface: #202124;
    --surface-muted: #2a2b2f;
    --text: #f3f3f4;
    --muted: #b4b6bd;
    --line: #44464d;
    --accent: #9bb7ff;
    --accent-soft: #243154;
    --correct: #9bb7ff;
    --correct-soft: #243154;
    --incorrect: #e2a391;
    --incorrect-soft: #402a23;
    --hint: #c4c7d0;
    --hint-soft: #303136;
    --complete: #9bb7ff;
    --complete-soft: #243154;
    --focus: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar,
.workspace-layout,
.workspace-main,
.lesson-panel,
.topic-panel,
.site-footer {
  width: 100%;
}

.topbar {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: 1440px;
  margin: 0 auto 18px;
  padding: 28px 96px 8px;
  text-align: center;
}

.topbar h1,
.lesson-header h2,
.panel-heading h2,
.progress-section h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-lockup {
  display: inline-flex;
  justify-content: center;
}

.brand-mark {
  margin: 0;
  color: var(--text);
  font-size: clamp(3.2rem, 8vw, 5.2rem);
  font-weight: 800;
  letter-spacing: -0.08em;
  line-height: 0.9;
}

.brand-mark sup {
  margin-left: 0.28em;
  color: var(--accent);
  font-size: 0.16em;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: super;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.data-actions,
.workspace-tools,
.mode-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.tool-button,
.mode-tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.icon-button,
.tool-button,
.mode-tab {
  min-height: 44px;
}

.icon-button {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  cursor: pointer;
}

.icon-button svg,
.tool-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.file-action input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

.site-footer {
  max-width: 1440px;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.workspace-main {
  display: grid;
  gap: 8px;
}

.topic-panel,
.progress-panel,
.lesson-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.topic-panel,
.progress-panel {
  padding: 14px;
}

.panel-heading p,
.progress-section p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel-heading h2,
.progress-section h2 {
  font-size: 15px;
}

.progress-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 28px;
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.progress-summary::-webkit-details-marker {
  display: none;
}

.progress-summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.progress-panel[open] .progress-summary::after {
  transform: rotate(225deg) translateY(-2px);
}

.progress-summary span:last-child {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.options-panel-body {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-top: 14px;
}

.options-panel-body .progress-section + .progress-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.device-note.compact {
  grid-column: 1 / -1;
  margin-top: 0;
}

.topic-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.topic-group {
  display: grid;
}

.topic-summary {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.topic-summary {
  display: flex;
  align-items: center;
  font-weight: 700;
  list-style: none;
}

.topic-summary::-webkit-details-marker {
  display: none;
}

.topic-summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.topic-group[open] .topic-summary::after {
  transform: rotate(225deg) translateY(-2px);
}

.lesson-list {
  display: grid;
  gap: 4px;
  padding: 6px 0 8px 14px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  background: var(--surface);
}

.topic-group[open] .topic-summary {
  border-radius: 6px 6px 0 0;
}

.curriculum-section {
  display: grid;
}

.curriculum-section-summary {
  display: flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  list-style: none;
  text-transform: uppercase;
}

.curriculum-section-summary::-webkit-details-marker {
  display: none;
}

.curriculum-section-summary::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}

.curriculum-section[open] .curriculum-section-summary::after {
  transform: rotate(225deg) translateY(-1px);
}

.curriculum-section-lessons {
  display: grid;
  gap: 2px;
}

.lesson-nav-button {
  min-height: 34px;
  width: 100%;
  padding: 0 10px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.lesson-nav-button[aria-current="true"] {
  border-left-color: var(--accent);
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.lesson-panel {
  padding: 16px;
}

.lesson-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.lesson-header h2 {
  font-size: 22px;
  line-height: 1.15;
}

.mode-tabs {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.mode-tab {
  min-width: 82px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

.mode-tab[aria-selected="true"] {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
}

.lesson-intro {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 18px 0 4px;
  border-top: 1px solid var(--line);
}

.lesson-intro[hidden] {
  display: none;
}

.lesson-intro h3 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.intro-copy ol {
  display: grid;
  gap: 10px;
  max-width: 680px;
  margin: 14px 0 0;
  padding-left: 22px;
  color: var(--text);
}

.intro-copy li::marker {
  color: var(--muted);
  font-weight: 700;
}

.intro-figure {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.intro-figure-grid {
  display: grid;
  grid-template-columns: 84px repeat(3, 44px);
  grid-auto-rows: 36px;
  gap: 4px;
  width: max-content;
  max-width: 100%;
  align-items: center;
}

.intro-cell {
  display: flex;
  min-width: 44px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  position: relative;
}

.intro-cell.label {
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}

.intro-cell.top-label {
  align-self: end;
  justify-content: center;
  text-align: center;
}

.intro-cell.operator {
  color: var(--muted);
}

.intro-cell.mark {
  min-width: 26px;
  min-height: 24px;
  align-self: end;
  justify-self: start;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 14px;
  z-index: 2;
}

.intro-cell.wide-mark {
  min-width: 34px;
}

.intro-cell.active-source,
.intro-cell.active-result {
  background: var(--accent-soft);
}

.intro-cell.exponent-cell {
  gap: 1px;
}

.intro-cell.exponent-cell sup {
  align-self: flex-start;
  margin-top: 5px;
  font-size: 0.58em;
  line-height: 1;
}

.intro-cell.result,
.intro-cell.active-result,
.intro-cell.empty,
.intro-cell.fraction-piece {
  border: 1px solid var(--line);
  background: var(--surface);
}

.intro-cell.wide-note {
  grid-column: 2 / 5 !important;
  justify-content: flex-start;
  min-width: 100%;
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.intro-cell.fraction-piece {
  border-radius: 0;
}

.intro-cell.empty {
  color: transparent;
}

.intro-cell.borrow-lent-demo::after {
  content: "";
  position: absolute;
  width: 24px;
  height: 2px;
  background: var(--text);
  transform: rotate(-28deg);
}

.intro-cell.division-divisor-demo {
  justify-content: flex-end;
  padding-right: 8px;
}

.intro-cell.division-digit-demo {
  border-top: 2px solid var(--text);
  border-radius: 0;
}

.intro-cell.division-digit-demo.active-source {
  border-left: 2px solid var(--text);
}

.intro-rule {
  min-height: 2px;
  border-top: 2px solid var(--text);
}

.intro-figure figcaption {
  max-width: 560px;
  color: var(--muted);
  font-size: 13px;
}

.lesson-setup {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  margin-top: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.lesson-setup[hidden] {
  display: none;
}

.lesson-setup h3 {
  margin: 0;
  font-size: 15px;
}

.problem-form {
  display: flex;
  align-items: end;
  gap: 8px;
  justify-content: end;
}

.problem-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.problem-form input {
  width: 88px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.device-note,
.activity-status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
}

.device-note {
  background: var(--surface-muted);
  color: var(--muted);
}

.activity-status {
  background: var(--accent-soft);
  color: var(--text);
  min-height: 44px;
}

.activity-status.correct {
  background: var(--correct-soft);
}

.activity-status.incorrect {
  background: var(--incorrect-soft);
}

.activity-status.hint {
  background: var(--hint-soft);
}

.activity-status.complete {
  background: var(--complete-soft);
}

.activity-grid-shell {
  position: relative;
  overflow-x: auto;
  margin-top: 18px;
  padding: 12px 0;
}

.math-grid {
  display: grid;
  grid-template-columns: 72px repeat(6, 44px);
  gap: 5px;
  width: max-content;
  min-width: 100%;
  justify-content: center;
  align-items: center;
}

.multiplication-grid {
  grid-template-rows: repeat(10, 44px);
}

.division-grid {
  grid-template-rows: repeat(11, 44px);
}

.concept-grid {
  grid-template-rows: minmax(160px, auto);
}

.equation-grid,
.inequality-grid {
  grid-template-columns: 92px minmax(92px, 128px) 44px minmax(92px, 128px);
  grid-template-rows: repeat(6, 48px);
  min-width: 0;
}

.addition-grid,
.subtraction-grid {
  grid-template-rows: repeat(5, 44px);
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 7px;
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  position: relative;
}

.grid-cell.active-column {
  background: var(--accent-soft);
}

.row-label {
  justify-content: flex-end;
  min-width: 72px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  text-align: right;
  white-space: nowrap;
}

.row-label[data-row-label="add-carry"] {
  opacity: 0;
}

.row-label[data-row-label="add-carry"].is-visible {
  opacity: 1;
}

.digit-static {
  background: transparent;
}

.grid-cell.active-column.digit-static {
  background: var(--accent-soft);
}

.concept-card {
  display: grid;
  gap: 16px;
  justify-self: center;
  width: min(100%, 620px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.concept-card.active-column {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.concept-prompt {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
}

.concept-answer-label {
  display: grid;
  gap: 6px;
  max-width: 220px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.concept-answer-input {
  width: 100%;
  min-width: 160px;
}

.concept-action {
  justify-self: start;
}

.equation-expression {
  min-width: 92px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 20px;
  white-space: nowrap;
}

.equation-input {
  width: 92px;
  font-size: 20px;
}

.operator {
  color: var(--muted);
}

.division-divisor {
  justify-content: flex-end;
  padding-right: 8px;
}

.division-digit {
  border-radius: 0;
}

.division-first {
  border-left: 2px solid var(--text);
}

.division-first::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  width: 142px;
  height: 2px;
  background: var(--text);
  z-index: 1;
}

.digit-input {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  appearance: textfield;
}

.digit-input[maxlength="2"] {
  width: 58px;
}

.digit-input[maxlength="3"] {
  width: 72px;
}

.digit-input::-webkit-outer-spin-button,
.digit-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.digit-input.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}

.digit-input.correct {
  border-color: var(--correct);
  background: var(--correct-soft);
}

.digit-input.incorrect {
  border-color: var(--incorrect);
  background: var(--incorrect-soft);
}

.digit-input.hint {
  border-color: var(--hint);
  background: var(--hint-soft);
}

.carry-slot-cell {
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0 0 3px 2px;
}

.borrow-superscript-slot {
  position: absolute;
  top: -14px;
  z-index: 2;
}

.borrow-recipient-slot {
  left: -7px;
}

.borrow-lender-slot {
  left: 15px;
}

.carry-input {
  width: 32px;
  height: 30px;
  font-size: 18px;
}

.carry-input[maxlength="2"] {
  width: 40px;
}

.borrow-superscript-input {
  width: 24px;
  height: 24px;
  font-size: 15px;
}


.grid-cell.borrow-lent::after {
  content: "";
  position: absolute;
  width: 24px;
  height: 2px;
  background: var(--text);
  transform: rotate(-28deg);
  transform-origin: center;
  z-index: 1;
}

.grid-line {
  min-height: 8px;
  border-top: 2px solid var(--text);
  border-radius: 0;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 420px;
  pointer-events: none;
}

.workspace-tools {
  flex-wrap: wrap;
  margin-top: 14px;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: var(--radius);
  cursor: pointer;
}

.tool-button.compact {
  padding: 0 12px;
}

.tool-button:first-child {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.progress-list {
  margin: 10px 0 0;
}

.progress-list div {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin-top: 10px;
}

.progress-list dt {
  color: var(--muted);
  font-size: 13px;
}

.progress-list dd {
  margin: 0;
  font-weight: 700;
}

.saved-workspaces {
  margin-top: 10px;
  padding: 10px;
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--muted);
}

.data-actions {
  margin-top: 10px;
}

.source-link {
  margin: 10px 0 0;
}

.source-link a {
  color: var(--accent);
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-top: 8px;
  color: var(--text);
  cursor: pointer;
}

.option-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

@media (max-width: 1120px) {
  .workspace-layout {
    grid-template-columns: minmax(170px, 220px) minmax(0, 1fr);
  }

}

@media (max-width: 980px) {
  .options-panel-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    padding: 12px 56px 4px;
  }

  .brand-mark {
    font-size: clamp(3rem, 15vw, 4.4rem);
  }

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .options-panel-body {
    grid-template-columns: 1fr;
  }

  .lesson-header {
    display: grid;
  }

  .lesson-setup {
    grid-template-columns: 1fr;
  }

  .problem-form {
    flex-wrap: wrap;
  }

  .mode-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .mode-tab {
    flex: 1 0 86px;
  }

  .math-grid {
    justify-content: start;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .icon-button,
  .tool-button,
  .mode-tab,
  .topic-summary,
  .lesson-nav-button,
  .digit-input {
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  }
}
