.isg {
  --isg-cell: clamp(42px, 8vw, 58px);
  --isg-ink: #172033;
  --isg-muted: #667085;
  --isg-accent: #3157d5;
  --isg-danger: #b42318;
  --isg-ok: #067647;
  --isg-paper: #fffef8;
  --isg-grid: rgba(70, 116, 180, 0.28);
  color: var(--isg-ink);
  font-family: ui-rounded, "SF Pro Rounded", Inter, system-ui, sans-serif;
}

.isg *,
.isg *::before,
.isg *::after {
  box-sizing: border-box;
}

.isg button,
.isg input {
  font: inherit;
}

.isg-panel {
  padding: clamp(12px, 2vw, 20px);
}

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

.isg-kicker {
  color: var(--isg-muted);
  font-size: 14px;
  margin: 0 0 4px;
}

.isg-title {
  margin: 0 0 4px;
  font-size: clamp(22px, 4vw, 30px);
}

.isg-limit {
  color: var(--isg-muted);
  font-size: 13px;
}

.isg-primary,
.isg-secondary,
.isg-source-button,
.isg-kind-button {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid #cfd4dc;
  background: #fff;
  color: var(--isg-ink);
  cursor: pointer;
  padding: 10px 14px;
}

.isg-primary {
  background: var(--isg-accent);
  color: #fff;
  border-color: var(--isg-accent);
  font-weight: 800;
}

.isg-secondary,
.isg-kind-button {
  font-weight: 650;
}

.isg-primary:disabled,
.isg-secondary:disabled,
.isg-tool:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.isg button:focus-visible,
.isg input:focus-visible {
  outline: 3px solid rgba(49, 87, 213, 0.28);
  outline-offset: 2px;
}

.isg-tool:focus-visible {
  outline: 3px solid rgba(49, 87, 213, 0.28);
  outline-offset: 2px;
}

.isg-cell:focus-visible,
.isg-borrow-input:focus-visible {
  outline: none;
}

.isg-toolbar,
.isg-actions,
.isg-source-row,
.isg-progress-row,
.isg-kind-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.isg-toolbar {
  margin: 0 0 12px;
  padding: 8px;
  border: 1px solid #e4e7ec;
  border-radius: 18px;
  background: #f4f6fb;
  gap: 8px;
}

.isg-stages {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 0 8px;
  margin: 0 0 4px;
  scrollbar-width: thin;
}

.isg-stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 32px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid #e4e7ec;
  background: #fff;
  color: #667085;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.isg-stage-pill:not(:disabled) { cursor: pointer; }
.isg-stage-pill:disabled { cursor: default; }
.isg-stage-pill[data-state="done"]:hover:not(:disabled) {
  border-color: #12b76a;
  background: #d1fadf;
}

.isg-stage-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f2f4f7;
  color: #475467;
  font-size: 11px;
}

.isg-stage-pill[data-state="current"] {
  border-color: #b2ccff;
  background: #eef4ff;
  color: #183a9c;
}

.isg-stage-pill[data-state="current"] .isg-stage-num {
  background: var(--isg-accent);
  color: #fff;
}

.isg-stage-pill[data-state="done"] {
  border-color: #abefc6;
  background: #ecfdf3;
  color: #067647;
}

.isg-stage-pill[data-state="done"] .isg-stage-num {
  background: #12b76a;
  color: #fff;
}

.isg-stage-pill[data-state="todo"] {
  opacity: 0.55;
}

.isg-stage-now {
  margin: 0 0 10px;
  color: #183a9c;
  font-size: 14px;
  font-weight: 800;
}

.isg-tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 12px 6px 6px;
  border: 0;
  border-radius: 13px;
  background: #fff;
  color: #1d2939;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 0 0 1px rgba(16, 24, 40, 0.04);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.01em;
  cursor: pointer;
}

.isg-tool-icon {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 10px;
  background: #eef2ff;
  color: #3538cd;
}

.isg-tool:hover {
  background: #f8fafc;
  box-shadow: 0 4px 10px rgba(16, 24, 40, 0.08), 0 0 0 1px rgba(49, 87, 213, 0.16);
}

.isg-tool[data-on="true"] .isg-tool-icon {
  background: #d1fadf;
  color: #067647;
}

.isg-tool-ghost {
  padding: 6px 12px;
  background: transparent;
  box-shadow: none;
  color: #475467;
  font-weight: 650;
}

.isg-tool-ghost:hover {
  background: #fff;
}

.isg-guide {
  margin: 8px 0 0;
  color: #1d4ed8;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
}

.isg-kind-row {
  margin: 12px 0 14px;
}

.isg-kind-button[data-active="true"] {
  border-color: var(--isg-accent);
  color: var(--isg-accent);
  background: #eef2ff;
}

.isg-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #eef2ff;
  color: #3538cd;
  font-size: 13px;
  font-weight: 700;
}

.isg-problem {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 14px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid #dbe4ff;
  border-radius: 16px;
  background: #f8faff;
}

.isg-problem-label {
  color: #475467;
  font-size: 14px;
  font-weight: 750;
}

.isg-problem-example {
  font-size: clamp(26px, 5vw, 36px);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.1;
  color: var(--isg-ink);
}

.isg-paper {
  border-radius: 18px;
  padding: 12px;
  overflow-x: auto;
  background-color: var(--isg-paper);
  box-shadow: inset 0 0 0 1px rgba(70, 116, 180, 0.22);
}

.isg-sheet {
  width: calc(var(--isg-cell) * 7);
  margin-left: auto;
  margin-right: auto;
  position: relative;
  background-image:
    linear-gradient(var(--isg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--isg-grid) 1px, transparent 1px);
  background-size: var(--isg-cell) var(--isg-cell);
  background-position: 0 0;
  box-shadow: inset 0 0 0 1px var(--isg-grid);
}

.isg-grid {
  width: calc(var(--isg-cell) * 7);
}

.isg-annotation-row,
.isg-number-row,
.isg-result-row,
.isg-place-labels {
  display: grid;
  grid-template-columns: repeat(7, var(--isg-cell));
  align-items: stretch;
  height: var(--isg-cell);
  margin: 0;
}

.isg-place-labels {
  width: calc(var(--isg-cell) * 7);
}

.isg-place-label {
  font-size: 10px;
  color: var(--isg-muted);
  text-align: center;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.isg-place-label[data-spot] {
  color: #183a9c;
  font-weight: 800;
  background: #eef4ff;
}

.isg-place-label[data-spot="source"] {
  color: #b54708;
  background: #fff6ed;
}

.isg-place-label[data-spot="target"] {
  color: #175cd3;
  background: #eff8ff;
}

.isg-sign {
  position: relative;
  font-size: 0;
  line-height: 0;
  overflow: visible;
}

.isg-sign::before {
  content: "−";
  position: absolute;
  right: 2px;
  bottom: calc(var(--isg-cell) - 0.38em);
  font-size: calc(var(--isg-cell) * 0.78);
  font-weight: 800;
  line-height: 1;
  color: var(--isg-ink);
}

.isg-cell {
  width: 100%;
  height: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: center;
  font-size: calc(var(--isg-cell) * 0.58);
  line-height: 1;
  font-weight: 700;
  color: var(--isg-ink);
  caret-color: var(--isg-accent);
  appearance: none;
  -moz-appearance: textfield;
}

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

.isg-cell[data-active="true"] {
  box-shadow: inset 0 0 0 3px var(--isg-accent);
  background: #f4f6ff;
}

.isg-cell[data-locked="true"] {
  background: transparent;
}

.isg-cell[data-error="true"] {
  box-shadow: inset 0 0 0 3px var(--isg-danger);
  background: #fff4f2;
}

.isg-cell[data-correct="true"] {
  background: #ecfdf3;
  box-shadow: inset 0 0 0 2px #75c9a5;
}

.isg-cell[data-struck="true"] {
  color: #98a2b3;
  text-decoration: line-through;
  font-weight: 650;
}

.isg-cell[data-spot="talk"],
.isg-cell[data-spot="target"] {
  background: #eef4ff;
  box-shadow: inset 0 0 0 3px #3157d5;
}

.isg-cell[data-spot="source"] {
  background: #fff6ed;
  box-shadow: inset 0 0 0 3px #dc6803;
}

.isg-cell[data-spot="chain"] {
  background: #f4f3ff;
  box-shadow: inset 0 0 0 3px #7a5af8;
}

.isg-cell[data-error="true"] {
  box-shadow: inset 0 0 0 3px var(--isg-danger);
  background: #fff4f2;
}

.isg-bottom-row {
  position: relative;
  box-shadow: 0 2px 0 0 var(--isg-ink);
}

.isg-borrow-input {
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  min-width: 0;
  max-width: 100%;
  margin: 3px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fff7ed;
  box-shadow: inset 0 0 0 2px #f7b27a;
  text-align: center;
  font-size: calc(var(--isg-cell) * 0.42);
  font-weight: 800;
  color: #b54708;
}

.isg-borrow-input::placeholder {
  color: #f7b27a;
  font-size: calc(var(--isg-cell) * 0.28);
  font-weight: 750;
}

.isg-borrow-input[data-role="target"] {
  background: #eff8ff;
  box-shadow: inset 0 0 0 2px #84caff;
  color: #175cd3;
}

.isg-borrow-input[data-role="target"]::placeholder {
  color: #84caff;
}

.isg-borrow-input[data-role="chain"] {
  background: #f4f3ff;
  box-shadow: inset 0 0 0 2px #bdb4fe;
  color: #5925dc;
}

.isg-borrow-input[data-role="chain"]::placeholder {
  color: #bdb4fe;
}

.isg-borrow-input[data-active="true"],
.isg-borrow-input[data-spot] {
  box-shadow: inset 0 0 0 3px #dc6803;
}

.isg-borrow-input[data-role="target"][data-active="true"],
.isg-borrow-input[data-role="target"][data-spot] {
  box-shadow: inset 0 0 0 3px #175cd3;
}

.isg-annotation-value {
  text-align: center;
  font-size: calc(var(--isg-cell) * 0.32);
  font-weight: 700;
  color: #475467;
  display: grid;
  place-items: center;
}

.isg-annotation-value.isg-borrow-kept {
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  margin: 3px;
  border-radius: 10px;
  font-size: calc(var(--isg-cell) * 0.42);
  font-weight: 800;
  background: #fff7ed;
  color: #b54708;
  box-shadow: inset 0 0 0 2px #f7b27a;
}

.isg-annotation-value.isg-borrow-kept[data-role="target"] {
  background: #eff8ff;
  color: #175cd3;
  box-shadow: inset 0 0 0 2px #84caff;
}

.isg-annotation-value.isg-borrow-kept[data-role="chain"] {
  background: #f4f3ff;
  color: #5925dc;
  box-shadow: inset 0 0 0 2px #bdb4fe;
}

.isg-annotation-value[data-spot] {
  box-shadow: inset 0 0 0 3px #dc6803;
}

.isg-hint {
  display: none !important;
}

.isg-source-panel {
  margin: 12px 0;
  padding: 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px dashed #98a2b3;
  width: 100%;
}

.isg-source-button[data-valid="true"] {
  border-color: var(--isg-accent);
}

.isg-source-button[data-zero="true"] {
  opacity: 0.7;
}

.isg-result-banner {
  padding: 16px;
  border-radius: 16px;
  background: #ecfdf3;
  border: 1px solid #abefc6;
  margin-top: 14px;
}

.isg-result-banner strong {
  font-size: 24px;
}

.isg-help {
  margin: 12px 0 0;
  color: #475467;
  font-size: 13px;
}

.isg-hidden {
  display: none !important;
}

.isg-intro {
  display: grid;
  gap: 16px;
  padding: 8px 2px 12px;
}

.isg-intro p {
  margin: 0;
  color: #334155;
  font-size: 17px;
  line-height: 1.55;
}

.isg-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.isg-example {
  min-width: 7.5rem;
  padding: 12px 16px;
  border: 1px solid #d0d5dd;
  border-radius: 14px;
  background: #fff;
  font-size: clamp(22px, 4vw, 28px);
  font-weight: 750;
  letter-spacing: 0.03em;
  text-align: center;
}

.isg-stage {
  margin: 0 0 10px;
  color: #3538cd;
  font-size: 13px;
  font-weight: 800;
}

.isg-work {
  margin-top: 8px;
  padding-top: 18px;
  border-top: 1px solid #e4e7ec;
}

.isg-board[data-mode="complete"] .isg-work {
  display: none;
}

.isg-board[data-mode="demo"] [data-isg="undoBtn"],
.isg-board[data-mode="check"] [data-isg="undoBtn"] {
  display: none;
}

.isg-check {
  display: grid;
  gap: 10px;
  width: 100%;
}

.isg-check-q {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
  color: var(--isg-ink);
}

.isg-check-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.isg-check-btns .isg-primary,
.isg-check-btns .isg-secondary {
  flex: 1 1 140px;
  min-height: 48px;
  font-size: 17px;
}

.isg-complete {
  display: grid;
  gap: 12px;
  padding: 8px 2px 4px;
}

.isg-complete p {
  margin: 0;
  color: #334155;
  font-size: 17px;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .isg-paper {
    border-radius: 14px;
    padding: calc(var(--isg-cell) * 0.5);
  }
}

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

/* Fit all seven notebook columns to the actual lesson width. */
.isg { container-type: inline-size; }
.isg-work { margin-top: 10px; padding-top: 0; border-top: 0; }
.isg-board[data-mode="intro"] .isg-hint,
.isg-board[data-mode="intro"] [data-isg="phaseActions"],
.isg-board[data-mode="intro"] [data-isg="repeatBtn"] { display: none; }
@media (max-width: 720px) {
  .isg { --isg-cell: min(44px, calc((100cqw - 32px) / 7)); }
  .isg-panel { padding: 10px; }
  .isg-kicker { display: none; }
  .isg-title { font-size: 20px; line-height: 1.3; }
  .isg-paper { padding: 6px; }
  .isg-stages { margin: 0; padding-bottom: 4px; }
  .isg-stage-now { margin-bottom: 6px; font-size: 13px; }
  .isg-toolbar { padding: 6px; margin-bottom: 8px; gap: 6px; }
  .isg-tool { min-height: 44px; padding: 6px 8px; font-size: 12px; }
  .isg-tool-icon { width: 26px; height: 26px; }
  .isg-problem { padding: 8px 10px; margin-bottom: 8px; gap: 6px 10px; }
  .isg-problem-example { font-size: 26px; }
  .isg-hint { margin: 10px 0; padding: 10px; }
  .isg-place-label { font-size: 8px; }
  .isg-actions > button { flex: 1 1 auto; min-height: 48px; }
}

/* One quiet control row; secondary actions open only when requested. */
.isg-toolbar { padding: 0; border: 0; background: transparent; border-radius: 0; gap: 8px; flex-wrap: nowrap; }
.isg-toolbar > [data-isg="startBtn"] { margin-right: auto; }
.isg-toolbar > .isg-tool { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; flex: 0 0 44px; border: 1px solid #e4e7ec; box-shadow: none; border-radius: 12px; }
.isg-toolbar > .isg-tool > span:not(.isg-tool-icon) { display: none; }
.isg-toolbar > .isg-tool .isg-tool-icon { width: 24px; height: 24px; background: transparent; }
.isg-toolbar > [data-isg="soundBtn"][data-on="true"] { background: #eef6f2; border-color: #d8e9df; }
.isg-more { position: relative; margin-left: auto; }
.isg-more > summary { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 0 12px; border-radius: 12px; color: #475467; font-size: 13px; font-weight: 650; cursor: pointer; list-style: none; }
.isg-more > summary::-webkit-details-marker { display: none; }
.isg-more > summary:hover, .isg-more[open] > summary { background: #f2f4f7; }
.isg-more > summary:focus-visible { outline: 3px solid #3157d5; outline-offset: 2px; }
.isg-more-panel { position: absolute; z-index: 5; top: calc(100% + 6px); right: 0; width: 224px; padding: 6px; border: 1px solid #e4e7ec; border-radius: 14px; background: #fff; box-shadow: 0 8px 24px #17203324; }
.isg-more-panel .isg-tool { width: 100%; min-height: 44px; box-shadow: none; font-size: 13px; padding: 8px; }
.isg-more-panel .isg-tool-ghost { padding-left: 8px; }
@media (max-width: 720px) {
  .isg-toolbar { margin-bottom: 8px; }
  .isg-title { font-size: 19px; letter-spacing: -.025em; }
  .isg-stages { gap: 4px; }
  .isg-stage-pill { font-size: 11px; }
}

.isg-toolbar > [data-isg="repeatBtn"] { width: auto; flex: 0 1 auto; padding: 0 10px; gap: 6px; font-size: 12px; white-space: nowrap; }
.isg-toolbar > [data-isg="repeatBtn"] > span:not(.isg-tool-icon) { display: inline; }
.isg-toolbar > [data-isg="skipBtn"]:not(.isg-hidden),
.isg-toolbar > .ng-admin-scrub:not(.isg-hidden) { margin-left: auto; flex: 0 0 auto; }
.isg-board[data-admin="1"] .ng-progress button:disabled { opacity: 1; }

@media (max-width: 360px) {
  .isg-more > summary { width: 44px; padding: 0; }
  .isg-more > summary > span:last-child { display: none; }
}

/* Unified OGE game shell: matches the number-decomposition lesson. */
.isg {
  --isg-shell-height: 650px;
  position: relative;
  height: var(--isg-shell-height);
  min-height: var(--isg-shell-height);
  max-height: var(--isg-shell-height);
  overflow: hidden;
  padding: 12px 12px 12px 58px;
}
.isg-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0;
}
.isg-header { flex: 0 0 auto; }
.isg-kicker { display: none; }
.isg-title {
  margin: 0 0 8px;
  font-size: clamp(20px, 2.4vw, 28px);
  line-height: 1.15;
  font-weight: 850;
}
.isg-work {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
/* Stages: shared .ng-progress from notebook-game.css */
.isg .ng-progress button {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  min-height: 30px;
  max-height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.isg .ng-progress button[data-state="todo"] { opacity: .55; }
.isg-board[data-admin="1"] .ng-progress button:disabled { opacity: 1; }
.isg-board[data-admin="1"] .ng-progress button[data-state="todo"] { opacity: 1; }

.isg-stage-now {
  min-height: 20px;
  margin: 0 0 10px;
  color: #667085;
  font-size: 13px;
  font-weight: 800;
}
.isg-toolbar {
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
}
.isg-paper {
  height: 305px;
  min-height: 305px;
  max-height: 305px;
  border-radius: 18px;
  overflow: auto;
  box-shadow: inset 0 0 0 1px rgba(70, 116, 180, .08);
}
.isg-hint {
  display: none !important;
}

@media (max-width: 720px) {
  .isg {
    --isg-shell-height: 650px;
    padding: 10px 8px 10px 46px;
  }
  .isg-panel { padding: 0; }
  .isg .ng-progress {
    left: 7px;
    top: 58px;
    bottom: 10px;
    width: 30px;
    gap: 8px;
  }
  .isg .ng-progress button {
    flex-basis: 28px;
    width: 28px;
    height: 28px;
    min-height: 28px;
  }
  .isg-paper {
    height: 305px;
    min-height: 305px;
    max-height: 305px;
  }
}
