.math-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: start;
  gap: 22px;
}

.math-topbar .stats {
  flex-wrap: wrap;
}

.math-board-wrap,
.math-panel,
.math-current-card,
.math-dialog {
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--glass-shadow);
}

.math-board-wrap {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.math-difficulty-bar {
  min-height: 64px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.math-difficulty-bar > span {
  color: var(--muted-strong);
  font-weight: 900;
}

.math-difficulty-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.math-difficulty,
.math-key {
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.math-difficulty {
  min-width: 78px;
  min-height: 44px;
  padding: 0 12px;
  box-shadow: 0 4px 0 rgba(112, 83, 39, 0.14);
}

.math-difficulty.active {
  color: #fff;
  background: #0891b2;
  border-color: #0e7490;
  box-shadow: 0 4px 0 #155e75;
}

.math-problems {
  display: grid;
  gap: 10px;
}

.math-problem {
  min-height: 72px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(76px, 96px) 48px;
  align-items: center;
  gap: 10px;
}

.math-problem.active {
  border-color: #4bb3fd;
  background: #eef8ff;
}

.math-problem.correct {
  border-color: #79c95c;
  background: #f1ffe8;
}

.math-problem.wrong {
  border-color: #f97316;
  background: #fff0e4;
}

.math-problem-number,
.math-problem-mark,
.math-problem-answer {
  display: grid;
  place-items: center;
}

.math-problem-number {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--muted-strong);
  font-size: 1.02rem;
}

.math-expression {
  min-width: 0;
  color: var(--ink);
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1;
}

.math-problem-answer {
  min-height: 46px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font-size: 1.42rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.math-problem.active .math-problem-answer {
  border-color: #4bb3fd;
}

.math-problem.correct .math-problem-answer {
  border-color: #79c95c;
}

.math-problem.wrong .math-problem-answer {
  border-color: #f97316;
}

.math-problem-mark {
  min-height: 32px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.math-problem.correct .math-problem-mark {
  color: #37933f;
  font-size: 1.45rem;
}

.math-problem.wrong .math-problem-mark {
  color: #d9571f;
  font-size: 1.28rem;
}

.math-panel {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.math-current-card {
  padding: 14px;
  display: grid;
  gap: 8px;
  box-shadow: none;
}

.math-current-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.math-current-card strong {
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.25;
}

.math-answer-display {
  min-height: 58px;
  border: 2px solid #4bb3fd;
  border-radius: var(--radius-sm);
  background: #eef8ff;
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.math-keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.math-key {
  min-height: 58px;
  box-shadow: 0 5px 0 rgba(112, 83, 39, 0.16);
  font-size: 1.35rem;
}

.math-key[data-key="clear"] {
  font-size: 0.92rem;
}

.math-key[data-key="enter"] {
  color: #fff;
  background: var(--grad-accent);
  border-color: #d95b20;
  box-shadow: 0 5px 0 #b9481c;
  font-size: 0.92rem;
}

.math-difficulty:hover,
.math-key:hover {
  transform: translateY(-2px);
  filter: brightness(1.03);
}

.math-difficulty:active,
.math-key:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(112, 83, 39, 0.18);
}

.stat--best {
  border-color: #f3b84d;
  background: #fff8dc;
}

.stat--best strong {
  color: var(--accent-strong);
}

.math-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: var(--radius);
  background: rgba(255, 244, 199, 0.78);
}

.math-dialog {
  width: min(460px, 100%);
  padding: 24px;
  border-color: #f3b84d;
  display: grid;
  gap: 16px;
  text-align: center;
}

.math-stars {
  color: #f59e0b;
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1;
}

.math-dialog h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1.8rem;
  line-height: 1.1;
}

.math-dialog p {
  margin: 0;
  color: var(--muted-strong);
  font-weight: 900;
  line-height: 1.45;
}

@media (max-width: 820px) {
  .math-view .topbar {
    display: grid;
  }

  .math-shell {
    grid-template-columns: 1fr;
  }

  .math-panel {
    grid-template-columns: 1fr 1.1fr;
    align-items: start;
  }

  .math-panel .actions,
  .math-panel .status-text {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .math-board-wrap,
  .math-panel {
    padding: 10px;
  }

  .math-difficulty-bar {
    display: grid;
  }

  .math-difficulty-options {
    justify-content: stretch;
  }

  .math-difficulty {
    flex: 1;
  }

  .math-problem {
    min-height: 62px;
    grid-template-columns: 34px minmax(0, 1fr) 70px 38px;
    gap: 7px;
    padding: 8px;
  }

  .math-problem-number {
    width: 30px;
    height: 30px;
  }

  .math-expression {
    font-size: 1.24rem;
  }

  .math-problem-answer {
    min-height: 40px;
    font-size: 1.14rem;
  }

  .math-problem-mark {
    font-size: 0.76rem;
  }

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

  .math-key {
    min-height: 54px;
  }

  .math-dialog {
    padding: 18px;
  }

  .math-dialog h2 {
    font-size: 1.45rem;
  }
}
