.math-trainer-page { max-width: 1040px; }
.math-trainer-intro { max-width: 820px; }
.math-trainer-intro .lede { max-width: 760px; }
.math-levels {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}
.math-level {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 14px 15px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease, transform .15s ease;
}
.math-level:hover:not(:disabled) { transform: translateY(-1px); border-color: #aeb4a5; }
.math-level.is-selected { border-color: #828d21; background: #f8fadf; box-shadow: 0 0 0 3px var(--accent-soft); }
.math-level:disabled { cursor: default; opacity: .72; }
.math-level span { color: #62695c; font-size: .64rem; font-weight: 900; letter-spacing: .075em; }
.math-level strong { font-size: 1rem; letter-spacing: -.02em; }
.math-level small { color: var(--muted); font-size: .7rem; line-height: 1.35; }

.math-trainer-shell {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}
.math-trainer-topbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--panel);
}
.math-stat,
.math-timer-stat {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-right: 1px solid var(--line);
}
.math-stat:last-child { border-right: 0; }
.math-stat span,
.math-timer-stat span { color: var(--muted); font-size: .67rem; font-weight: 850; letter-spacing: .055em; text-transform: uppercase; }
.math-stat strong,
.math-timer-stat strong { font-size: 1.52rem; line-height: 1; }
.math-timer-stat em { color: var(--muted); font-size: .66rem; font-style: normal; font-weight: 800; }
.math-timer-track { height: 5px; background: #e9ece4; }
.math-timer-track span { display: block; width: 100%; height: 100%; background: var(--accent); transition: width .18s linear, background .18s ease; }
.math-timer-track span.is-low { background: #d87358; }

.math-game-area {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 30px 32px;
}
.math-question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.math-question-head .section-kicker { margin-bottom: 2px; }
.math-question-count { color: var(--muted); font-size: .76rem; font-weight: 750; }
.math-reset { min-height: 36px; padding: 7px 11px; }
.math-question-card {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 34px 24px 26px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #fbfcf7 0%, #f5f7ef 100%);
  text-align: center;
}
.math-question-card::before,
.math-question-card::after {
  content: "";
  position: absolute;
  width: 150px;
  height: 150px;
  border: 1px solid #e4e8dc;
  border-radius: 50%;
}
.math-question-card::before { top: -86px; left: -58px; }
.math-question-card::after { right: -70px; bottom: -96px; }
.math-question-level {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 5px 9px;
  border: 1px solid #d4d9c9;
  border-radius: 999px;
  background: #fff;
  color: #62695c;
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .075em;
}
.math-question {
  position: relative;
  z-index: 1;
  margin-top: 10px;
  color: var(--text);
  font-size: clamp(2rem, 6vw, 3.65rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -.055em;
}
.math-question-card p {
  position: relative;
  z-index: 1;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.4;
}
.math-desktop-entry { margin-top: 18px; }
.math-desktop-entry > label { display: block; margin-bottom: 6px; color: var(--text); font-size: .68rem; font-weight: 900; letter-spacing: .055em; }
.math-answer-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 15px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.math-answer-input:focus-within { border-color: #879224; box-shadow: 0 0 0 3px var(--accent-soft); }
.math-answer-input input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 14px 0;
  color: var(--text);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 850;
}
.math-answer-input input:disabled { color: #a1a49c; }
.math-answer-input span { color: var(--muted); font-size: .76rem; font-weight: 800; }
.math-desktop-entry p { margin: 7px 0 0; color: var(--muted); font-size: .7rem; }

.math-desktop-fraction-tools {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f9f3;
}
.math-desktop-fraction-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.math-desktop-fraction-heading span { color: var(--text); font-size: .62rem; font-weight: 900; letter-spacing: .055em; }
.math-desktop-fraction-heading small { color: var(--muted); font-size: .62rem; }
.math-desktop-fraction-pad {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
}
.math-desktop-fraction-pad button {
  min-height: 34px;
  padding: 5px 4px;
  border: 1px solid #cfd3ca;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: .7rem;
  font-weight: 850;
  cursor: pointer;
}
.math-desktop-fraction-pad button:hover:not(:disabled) { border-color: #a7ad9d; background: #fbfcf8; }
.math-desktop-fraction-pad button:focus-visible { outline: 2px solid #778116; outline-offset: 2px; }
.math-desktop-fraction-pad button.is-selected { border-color: #778116; background: var(--accent); color: #1f251e; }
.math-desktop-fraction-pad button:disabled { opacity: .5; cursor: default; }
.math-feedback {
  margin-top: 12px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: .78rem;
  line-height: 1.45;
}
.math-feedback strong { font-weight: 900; }
.math-feedback.is-correct { border-color: #d6e477; background: #f5f8dc; }
.math-feedback.is-wrong { border-color: #efc8bf; background: #fff4f1; }
.math-feedback.is-summary { border-color: #cbd1c2; background: #f5f6f2; }
.math-primary { width: 100%; min-height: 48px; margin-top: 14px; }
.math-mobile-entry { display: none; }

.math-level-guide {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.math-level-guide > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}
.math-level-guide span { display: block; color: #697060; font-size: .62rem; font-weight: 900; letter-spacing: .065em; }
.math-level-guide strong { display: block; margin-top: 4px; font-size: .86rem; }
.math-level-guide p { margin: 5px 0 0; color: var(--muted); font-size: .7rem; line-height: 1.4; }
.math-level-guide + .resource-inline-callout { margin-top: 22px; }

@media (max-width: 680px) {
  .math-trainer-intro { padding-bottom: 18px; }
  .math-trainer-intro h1 { font-size: clamp(2rem, 10vw, 2.65rem); }
  .math-trainer-intro .lede { font-size: .88rem; line-height: 1.5; }

  .math-levels { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
  .math-level { min-height: 82px; padding: 9px 8px; border-radius: 11px; text-align: center; }
  .math-level span { font-size: .52rem; letter-spacing: .02em; white-space: nowrap; }
  .math-level strong { font-size: .76rem; }
  .math-level small { font-size: .55rem; line-height: 1.2; }

  .math-trainer-shell { border-radius: 15px; }
  .math-trainer-topbar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .math-stat,
  .math-timer-stat {
    min-height: 49px;
    gap: 3px;
    padding: 7px 3px;
    flex-direction: column;
    border-right: 1px solid var(--line);
  }
  .math-stat span,
  .math-timer-stat span { font-size: .54rem; letter-spacing: .035em; }
  .math-stat strong,
  .math-timer-stat strong { font-size: 1.12rem; }
  .math-timer-stat em { display: none; }
  .math-timer-track { height: 4px; }

  .math-game-area { padding: 10px 10px 13px; }
  .math-question-head { margin-bottom: 7px; }
  .math-question-head .section-kicker { font-size: .57rem; }
  .math-question-count { font-size: .62rem; }
  .math-reset { min-height: 30px; padding: 4px 6px; border: 0; background: transparent; color: var(--muted); font-size: .62rem; text-decoration: underline; text-underline-offset: 2px; }

  .math-question-card { min-height: 132px; padding: 18px 12px 15px; border-radius: 13px; }
  .math-question-card::before,
  .math-question-card::after { display: none; }
  .math-question-level { min-height: 22px; padding: 3px 7px; font-size: .52rem; }
  .math-question { margin-top: 7px; font-size: clamp(1.78rem, 9vw, 2.45rem); letter-spacing: -.045em; }
  .math-question-card p { margin-top: 7px; font-size: .61rem; }

  .math-desktop-entry { display: none; }
  .math-mobile-entry { display: block; margin-top: 7px; }
  .math-mobile-answer-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 45px;
    padding: 8px 11px;
    border: 2px solid var(--line);
    border-radius: 11px;
    background: #fff;
  }
  .math-mobile-answer-display span { color: var(--muted); font-size: .58rem; font-weight: 900; letter-spacing: .05em; }
  .math-mobile-answer-display strong { font-size: 1.2rem; letter-spacing: -.025em; }

  .math-mobile-pad {
    margin-top: 6px;
    padding: 7px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #f8f9f3;
    transition: opacity .12s ease;
  }
  .math-mobile-pad.is-disabled { opacity: .48; pointer-events: none; }
  .math-pad-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 5px; padding: 0 2px; }
  .math-pad-heading span { color: var(--text); font-size: .56rem; font-weight: 900; letter-spacing: .05em; }
  .math-pad-heading small { color: var(--muted); font-size: .53rem; }
  .math-whole-pad {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 5px;
    padding: 1px;
  }
  .math-fraction-pad {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    padding: 1px 1px 5px;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .math-fraction-pad::-webkit-scrollbar { display: none; }
  .math-fraction-heading { margin-top: 2px; }
  .math-whole-pad button,
  .math-fraction-pad button {
    height: 35px;
    border: 1px solid #cfd3ca;
    border-radius: 9px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: .7rem;
    font-weight: 850;
    cursor: pointer;
  }
  .math-whole-pad button { width: 100%; }
  .math-whole-pad button[data-action] { color: var(--muted); font-size: .62rem; }
  .math-fraction-pad button { flex: 0 0 40px; scroll-snap-align: center; }
  .math-fraction-pad button { flex-basis: 48px; font-size: .62rem; }
  .math-fraction-pad button:first-child { flex-basis: 52px; }
  .math-whole-pad button.is-selected,
  .math-fraction-pad button.is-selected { border-color: #778116; background: var(--accent); color: #1f251e; }

  .math-feedback { margin-top: 7px; padding: 8px 10px; border-radius: 10px; font-size: .68rem; }
  .math-primary { min-height: 44px; margin-top: 7px; }

  .math-level-guide { grid-template-columns: 1fr; gap: 7px; margin-top: 12px; }
  .math-level-guide > div { padding: 10px 11px; }
  .math-level-guide span { font-size: .56rem; }
  .math-level-guide strong { font-size: .76rem; }
  .math-level-guide p { font-size: .64rem; }
}

@media (max-width: 380px) {
  .math-level { padding-left: 5px; padding-right: 5px; }
  .math-level strong { font-size: .7rem; }
  .math-level small { font-size: .51rem; }
  .math-question { font-size: 1.7rem; }
}
