:root {
  --ink: #20382f;
  --green: #17634c;
  --muted: #66776e;
  --line: #dce4db;
  --lime: #e5efbd;
  --cream: #f5f6f0;
  --orange: #865126;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font:
    16px/1.6 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
}
a {
  color: var(--green);
  text-underline-offset: 4px;
}
button,
input,
textarea,
select {
  font: inherit;
}
button {
  cursor: pointer;
  border: 1px solid #c8d6cd;
  background: white;
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 15px;
  font-weight: 600;
}
button:hover {
  background: #edf3e9;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid #abcf65;
  outline-offset: 3px;
}
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
input,
textarea,
select {
  width: 100%;
  border: 1px solid #baccc0;
  border-radius: 9px;
  background: white;
  color: var(--ink);
  padding: 11px 13px;
}
textarea {
  resize: vertical;
  min-height: 80px;
}
input.math-input {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1.25rem;
}
input::placeholder,
textarea::placeholder {
  color: #839087;
  font-size: 0.95rem;
}
label {
  display: block;
  font-weight: 600;
  margin: 0 0 9px;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px max(24px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line);
  gap: 20px;
  background: #fff;
}
.brand {
  font-weight: 700;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.mark {
  background: var(--green);
  color: var(--lime);
  font: italic 28px Georgia;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  width: 35px;
  height: 35px;
}
.shell {
  max-width: 1240px;
  margin: auto;
  padding: 36px 24px 32px;
}
.intro {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 20px;
}
.eyebrow,
.question-top label {
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  color: var(--green);
}
h1 {
  font:
    400 clamp(1.9rem, 3.3vw, 2.65rem)/1.15 Georgia,
    serif;
  letter-spacing: -0.025em;
  margin: 11px 0;
}
h2 {
  font-size: 1.2rem;
  line-height: 1.35;
  margin: 0 0 12px;
}
p {
  margin: 8px 0 16px;
}
.intro p:not(.eyebrow) {
  color: var(--muted);
}
.save-status {
  font-size: 0.75rem;
  white-space: nowrap;
  margin-top: 18px;
  color: var(--green);
}
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  flex-wrap: wrap;
  margin: 18px 0 25px;
}
.modes {
  background: #e6eade;
  border-radius: 11px;
  padding: 4px;
  display: flex;
}
.modes button {
  border: 0;
  background: transparent;
}
.modes button[aria-pressed='true'] {
  background: white;
  box-shadow: 0 1px 5px #172a2012;
}
.exports {
  display: flex;
  gap: 8px;
}
.exports button {
  font-size: 0.8rem;
  background: transparent;
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 28px;
  align-items: start;
}
.paper {
  background: white;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 25px;
  margin-bottom: 18px;
  box-shadow: 0 3px 12px #20382f03;
}
.question {
  border-top: 4px solid var(--green);
}
.question-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}
.question select {
  font-size: 0.9rem;
  margin-bottom: 25px;
}
.question h2 {
  font-size: 1rem;
  color: var(--green);
  margin-bottom: 7px;
}
.expression {
  font:
    400 2.35rem/1.5 Georgia,
    serif;
  overflow-wrap: anywhere;
}
.pill {
  border-radius: 20px;
  background: #f0f3e9;
  padding: 3px 10px;
  white-space: nowrap;
  font-size: 0.75rem;
}
.progress-track {
  display: flex;
  gap: 6px;
  margin-top: 22px;
}
.progress-track span {
  height: 5px;
  background: #e5eadd;
  flex: 1;
  border-radius: 4px;
}
.progress-track span.done {
  background: var(--green);
}
.step {
  position: relative;
}
.step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.step-number {
  display: inline-grid;
  place-items: center;
  flex: 0 0 27px;
  height: 27px;
  border-radius: 50%;
  background: #edf3e6;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 700;
}
.step-head h3 {
  font-size: 1rem;
  margin: 0;
  flex: 1;
}
.step-state {
  font-size: 0.73rem;
  color: var(--green);
}
.prompt-math {
  font:
    1.4rem Georgia,
    serif;
  margin-bottom: 16px;
  padding: 15px;
  background: #f7f8f3;
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.step label {
  font-size: 0.86rem;
}
.preview {
  font:
    1.25rem/1.5 Georgia,
    serif;
  min-height: 32px;
  margin-top: 10px;
  overflow-wrap: anywhere;
  color: #395247;
}
.preview::before {
  content: 'You wrote: ';
  font: 12px system-ui;
  color: var(--muted);
}
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 13px;
}
.primary {
  background: var(--green);
  color: white;
  border-color: var(--green);
}
.primary:hover {
  background: #104d3c;
}
.hint-button {
  border: 0;
  text-decoration: underline;
  background: transparent;
  font-weight: 500;
}
.feedback {
  margin: 14px 0 0;
  padding: 12px 15px;
  background: #eef5e9;
  border-radius: 8px;
  font-size: 0.9rem;
}
.feedback.retry {
  background: #fff4e7;
  color: #75481e;
}
.hint {
  border-left: 3px solid #b7c994;
  padding: 6px 15px;
  margin: 14px 0 0;
  font-size: 0.9rem;
  background: #f6f8ef;
}
.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.choices button {
  text-align: left;
  font-weight: 500;
}
.choices button.selected {
  border: 2px solid var(--green);
  background: #f1f6e8;
}
.small,
.muted {
  color: var(--muted);
  font-size: 0.8rem;
}
.key-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.key-grid button {
  font-size: 1.15rem;
  position: relative;
  padding: 6px;
}
.key-grid small {
  font-size: 0.6rem;
  color: var(--muted);
}
aside h2 {
  font-size: 1rem;
}
aside p {
  font-size: 0.84rem;
}
aside .paper {
  padding: 20px;
}
.reminders details {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}
.example {
  font:
    1.05rem Georgia,
    serif;
}
.reminders > a {
  display: block;
  font-size: 0.85rem;
  margin-top: 18px;
}
.notes label {
  font-size: 0.9rem;
}
.free-line {
  margin: 20px 0;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}
.free-line label {
  font-size: 0.9rem;
}
.free-line textarea {
  margin-top: 8px;
  font-size: 0.85rem;
  min-height: 60px;
}
.finish {
  background: #edf4dd;
  border-color: #cbdcb1;
}
.finish h2 {
  font-family: Georgia, serif;
  font-size: 1.5rem;
}
.solution-line {
  font:
    1.3rem Georgia,
    serif;
  margin: 12px 0;
}
.storage-note {
  padding: 0 8px;
}
footer {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 25px;
}
.notes {
  margin-top: 18px;
}
[hidden] {
  display: none !important;
}
@media (max-width: 850px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  aside {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  aside .storage-note {
    grid-column: 1/-1;
  }
  .intro {
    display: block;
  }
  .save-status {
    display: block;
    margin-top: 4px;
  }
  .shell {
    padding: 24px 16px;
  }
  .top {
    padding: 16px;
  }
  .top > a:last-child {
    font-size: 0.8rem;
  }
  .question select {
    max-width: 100%;
  }
  .paper {
    padding: 21px;
  }
}
@media (max-width: 500px) {
  aside {
    display: block;
  }
  .exports {
    width: 100%;
  }
  .toolbar {
    gap: 9px;
  }
  .modes {
    width: 100%;
  }
  .modes button {
    flex: 1;
    padding: 9px 8px;
    font-size: 0.9rem;
  }
  .question-top {
    display: block;
  }
  .question-top .pill {
    display: inline-block;
    margin-bottom: 12px;
  }
  .step-head {
    flex-wrap: wrap;
  }
  .step-state {
    margin-left: 37px;
  }
  .expression {
    font-size: 2rem;
  }
}
@media print {
  body {
    background: white;
    color: black;
    font-size: 11pt;
  }
  .top,
  .toolbar,
  aside,
  .question select,
  .question-top label,
  .actions,
  .choices button:not(.selected),
  .progress-track,
  footer,
  .save-status,
  #add-line {
    display: none;
  }
  .shell {
    padding: 0;
  }
  .layout {
    display: block;
  }
  .paper {
    border: 0;
    border-bottom: 1px solid #bbb;
    border-radius: 0;
    box-shadow: none;
    break-inside: avoid;
    padding: 15px 0;
  }
  .intro h1 {
    font-size: 25pt;
  }
  .intro .eyebrow {
    display: none;
  }
  input,
  textarea {
    border: 0;
    padding: 4px 0;
    resize: none;
  }
  .expression {
    font-size: 24pt;
  }
  .feedback,
  .hint {
    padding: 8px;
    background: none;
  }
  .preview {
    display: none;
  }
  .choices button.selected {
    border: 0;
    background: none;
  }
  .notes {
    break-inside: avoid;
  }
}
@media (min-width: 851px) {
  .layout > aside {
    position: sticky;
    top: 18px;
  }
}
@media (max-width: 850px) {
  body {
    padding-bottom: 100px;
  }
  .keys {
    position: fixed;
    bottom: 10px;
    left: 12px;
    right: 12px;
    z-index: 5;
    margin: 0 !important;
    padding: 10px !important;
    box-shadow: 0 3px 24px #20382f30 !important;
  }
  .keys h2,
  .keys p {
    display: none;
  }
  .keys .key-grid {
    display: flex;
    gap: 5px;
  }
  .key-grid button {
    flex: 1;
    min-width: 0;
    padding: 8px 0;
  }
  .key-grid small {
    display: none;
  }
}
.print-value {
  display: none;
}
@media print {
  #restart {
    display: none;
  }
  .print-value {
    display: block;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 12pt;
  }
  .print-value + input,
  .print-value + textarea {
    display: none;
  }
  .layout > aside {
    display: none !important;
  }
}
dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: 90vh;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  color: var(--ink);
}
dialog::backdrop {
  background: #132e2466;
}
dialog textarea {
  font:
    14px/1.5 ui-monospace,
    monospace;
  max-height: 45vh;
}
dialog .actions {
  flex-wrap: wrap;
}
@media print {
  dialog {
    display: none !important;
  }
}
.visual-explanation {
  margin-top: 18px;
  border: 1px solid #cfddbd;
  background: #f6f9ee;
  border-radius: 12px;
  padding: 18px;
}
.visual-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--green);
  font-weight: 700;
}
.visual-top button {
  padding: 0 8px;
  font-size: 22px;
  border: 0;
  background: transparent;
}
.visual-scene {
  animation: scene-in 0.4s ease-out;
  min-height: 185px;
}
.visual-scene h4 {
  margin: 10px 0;
  font-size: 1rem;
}
.visual-scene p {
  margin: 15px 0 0;
  font-size: 0.9rem;
}
.visual-formula {
  font:
    1.65rem/1.6 Georgia,
    serif;
  padding: 15px 0;
  overflow-wrap: anywhere;
}
.factor-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 8px 0;
}
.math-chip {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  padding: 5px 10px;
  background: white;
  border: 1px solid #cbd7c7;
  border-radius: 8px;
  font:
    1.4rem Georgia,
    serif;
  position: relative;
  transition:
    background 0.4s,
    transform 0.4s;
}
.coefficient-chip {
  background: #f9e6d2;
  color: #824616;
}
.variable-chip {
  background: #e1eddd;
  color: var(--green);
}
.neutral-chip {
  opacity: 0.5;
}
.cancelled {
  color: #718070;
  background: #e6eae0;
}
.cancelled:after {
  content: '';
  position: absolute;
  height: 2px;
  left: 3px;
  right: 3px;
  top: 50%;
  background: #aa5543;
  transform: rotate(-38deg);
  animation: strike-in 0.6s ease-out;
}
.fraction-line {
  border-top: 2px solid #658165;
  margin: 8px 0;
}
.factor-fraction {
  max-width: 440px;
  margin: 16px auto;
}
.between-terms {
  text-align: center;
}
.shared,
.glow {
  background: #e2efb1;
  border-color: #82a34c;
  animation: gentle-pulse 1s ease-out;
}
.distribution {
  max-width: 320px;
  margin: 15px auto;
  text-align: center;
}
.inside-pair {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}
.branch-lines {
  display: flex;
  justify-content: space-around;
  font-size: 35px;
  line-height: 1.4;
  color: #b4c5a3;
}
.branch-lines .active {
  color: var(--green);
  animation: arrow-in 0.6s ease-out;
}
.visual-rule {
  font-size: 1.1rem;
  border-left: 3px solid #99b870;
  padding: 10px 15px;
}
.times {
  color: #7e8d80;
}
@keyframes scene-in {
  from {
    opacity: 0.3;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes strike-in {
  from {
    opacity: 0;
    transform: rotate(-38deg) scaleX(0);
  }
  to {
    opacity: 1;
    transform: rotate(-38deg) scaleX(1);
  }
}
@keyframes gentle-pulse {
  0% {
    transform: scale(0.95);
  }
  50% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes arrow-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *:before,
  *:after {
    animation: none !important;
    transition: none !important;
  }
}
@media print {
  .visual-explanation {
    display: none;
  }
}
