.math-exercise {
  --me-border: #d8dce3;
  --me-soft: #f5f7fa;
  --me-text: #18202a;
  --me-muted: #667085;
  --me-accent: #2357d9;
  --me-success: #157347;
  --me-danger: #b42318;
  --me-highlight: #fff0a8;

  box-sizing: border-box;
  width: min(100%, 720px);
  color: var(--me-text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

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

.me-equation-card {
  --me-border: #d8dce3;
  --me-text: #18202a;
  --me-highlight: #fff0a8;

  min-height: 150px;
  padding: 32px 24px;
  border: 1px solid var(--me-border);
  border-radius: 18px;
  background: white;
  color: var(--me-text);
  display: flex;
  align-items: center;
  overflow: hidden;
  font-family: "Times New Roman", Cambria, "STIX Two Math", serif;
  font-size: clamp(2rem, 7vw, 3.25rem);
  line-height: 1.15;
}

.me-equation-stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 3.85em;
  width: 100%;
  row-gap: 0;
}

.me-equation-stage.has-next-line {
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  row-gap: 0.45em;
}

.me-equation-stage.has-next-line.is-promoting {
  grid-template-rows: 0fr minmax(0, 1fr);
  row-gap: 0;
}

.me-equation-line {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.me-equation-scroll {
  display: flex;
  min-height: 1.7em;
  align-items: center;
  justify-content: center;
  overflow-x: auto;
  overflow-y: hidden;
}

.me-node {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  border-radius: 0.18em;
}

.me-row,
.me-term,
.me-factor,
.me-equation,
.me-power,
.me-explicit-group,
.me-auto-group {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}

.me-equation {
  gap: 0.32em;
  align-items: center;
}

.me-equals {
  padding: 0 0.08em;
}

.me-operator {
  display: inline-block;
  padding: 0 0.2em;
}

.me-unary {
  padding-left: 0;
}

.me-multiply-operator {
  display: inline-block;
  padding: 0 0.12em;
}

.me-bracket {
  display: inline-block;
  padding: 0 0.04em;
}

.me-fraction {
  display: inline-grid;
  grid-template-rows: auto 0.055em auto;
  align-items: center;
  justify-items: stretch;
  vertical-align: middle;
  min-width: 0.75em;
  margin: 0 0.07em;
  line-height: 1;
}

.me-numerator,
.me-denominator {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.08em 0.14em;
  font-size: 0.82em;
}

.me-fraction-line {
  display: block;
  width: 100%;
  min-width: 0.7em;
  height: 0.055em;
  background: currentColor;
}

.me-exponent {
  position: relative;
  top: -0.28em;
  margin-left: 0.04em;
  font-size: 0.62em;
  line-height: 1;
}

.me-step-copy {
  margin-top: 14px;
}

.me-step-explanation {
  font-weight: 650;
}

.me-frame-caption {
  margin-top: 4px;
  color: var(--me-muted);
  font-size: 0.94rem;
}

.me-answer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.me-answer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 650;
}

.me-answer input,
.me-answer select {
  width: 110px;
  padding: 10px 12px;
  border: 1px solid var(--me-border);
  border-radius: 10px;
  background: white;
  color: inherit;
  font: inherit;
  outline: none;
}

.me-answer-choice select {
  width: min(280px, 100%);
}

.me-answer input:focus,
.me-answer select:focus {
  border-color: var(--me-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--me-accent) 16%, transparent);
}

.me-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.me-button {
  appearance: none;
  border: 1px solid var(--me-border);
  border-radius: 10px;
  padding: 10px 14px;
  background: white;
  color: inherit;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.me-button:hover:not(:disabled) {
  background: var(--me-soft);
}

.me-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.me-button-primary {
  border-color: var(--me-accent);
  background: var(--me-accent);
  color: white;
}

.me-button-primary:hover:not(:disabled) {
  background: var(--me-accent);
  filter: brightness(0.96);
}

.me-feedback,
.me-hint,
.me-finished {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
}

.me-feedback-correct {
  background: color-mix(in srgb, var(--me-success) 10%, white);
  color: var(--me-success);
}

.me-feedback-incorrect {
  background: color-mix(in srgb, var(--me-danger) 9%, white);
  color: var(--me-danger);
}

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

.me-finished {
  background: var(--me-soft);
  color: var(--me-muted);
}

.me-word-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  color: var(--me-muted);
  font-size: 0.9rem;
}

.me-word-card {
  padding: 22px 24px;
  border: 1px solid var(--me-border);
  border-radius: 18px;
  background: white;
}

.me-word-kicker {
  margin-bottom: 8px;
  color: var(--me-accent);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.me-word-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 650;
  line-height: 1.65;
}

.me-word-values {
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--me-border);
  border-radius: 14px;
  background: white;
}

.me-word-values h4 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
}

.me-word-values dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.me-word-values dl > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--me-border) 70%,
    transparent);
}

.me-word-values dl > div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.me-word-values dt {
  color: var(--me-muted);
}

.me-word-values dd {
  margin: 0;
  font-weight: 700;
}

.me-word-guidance {
  margin-top: 4px;
}

.me-word-progress {
  margin-top: 16px;
}

.me-word-equation-phase > .me-feedback {
  margin-top: 18px;
}

.me-word-solution {
  margin-top: 28px;
  padding-top: 28px;
  border-top: 1px solid var(--me-border);
}

.me-progress {
  display: flex;
  gap: 6px;
  margin-top: 18px;
}

.me-progress-dot {
  appearance: none;
  padding: 0;
  border: 0;
  width: 28px;
  height: 5px;
  border-radius: 999px;
  background: var(--me-border);
}

.me-progress-dot.is-done {
  background: var(--me-accent);
}

.me-progress-dot.is-current {
  outline: 2px solid color-mix(in srgb, var(--me-accent) 35%, transparent);
  outline-offset: 2px;
}

.me-progress-dot.is-clickable {
  cursor: pointer;
}

.me-progress-dot.is-clickable:focus-visible {
  outline: 2px solid var(--me-accent);
  outline-offset: 3px;
}

@media (max-width: 560px) {
  .me-equation-card {
    min-height: 125px;
    padding: 24px 14px;
  }

  .me-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .me-button {
    width: 100%;
  }

  .me-word-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .me-word-card,
  .me-word-values {
    padding: 18px 16px;
  }
}

.me-equation-stage {
  transition:
    grid-template-rows var(--me-row-transition, 420ms) ease,
    row-gap var(--me-row-transition, 420ms) ease;
}

.me-equation-scroll {
  transition:
    opacity var(--me-row-transition, 420ms) ease,
    transform var(--me-row-transition, 420ms) ease;
}

.me-equation-line-next .me-equation-scroll {
  animation: me-equation-line-enter var(--me-row-transition, 420ms) ease both;
}

.me-equation-stage.is-promoting .me-equation-line-current .me-equation-scroll {
  opacity: 0;
  transform: translateY(-0.45em);
}

.me-equation-stage.is-promoting .me-equation-line-next .me-equation-scroll {
  animation: none;
}

.me-node {
  transition:
    opacity var(--me-node-transition, 180ms) ease,
    background-color var(--me-node-transition, 180ms) ease,
    transform var(--me-node-transition, 180ms) ease;
}

.me-highlight {
  background: var(--me-highlight);
  animation: me-pop var(--me-highlight-pop, 280ms) ease both;
}

.me-muted {
  opacity: 0.36;
}

.me-cancel {
  isolation: isolate;
}

.me-cancel::after {
  content: "";
  position: absolute;
  z-index: 3;
  left: -8%;
  top: 50%;
  width: 116%;
  height: 0.06em;
  min-height: 2px;
  background: currentColor;
  transform: rotate(-38deg) scaleX(0);
  transform-origin: left center;
  border-radius: 999px;
  pointer-events: none;
  animation: me-strike var(--me-strike-duration, 420ms)
    var(--me-strike-delay, 120ms) ease forwards;
}

@keyframes me-strike {
  to {
    transform: rotate(-38deg) scaleX(1);
  }
}

@keyframes me-pop {
  from {
    transform: scale(0.94);
  }
  to {
    transform: scale(1);
  }
}

@keyframes me-equation-line-enter {
  from {
    opacity: 0;
    transform: translateY(0.45em);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .me-node,
  .me-equation-stage,
  .me-equation-scroll {
    transition: none;
  }

  .me-equation-line-next .me-equation-scroll,
  .me-highlight {
    animation: none;
  }

  .me-cancel::after {
    animation: none;
    transform: rotate(-38deg) scaleX(1);
  }
}
