
.math-header a { text-decoration: none; }
.math-nav { gap: 8px; display: flex; }
.math-nav a { border-radius: 12px; padding: 10px 14px; font-weight: 800; color: var(--ink); }
.math-nav a:hover, .math-nav a.active { color: var(--green); background: #e8f1e8; }
.math-page { padding-block: 24px 70px; }
.math-back { display: inline-block; text-decoration: none; margin-bottom: 14px; }
.math-view[hidden] { display: none !important; }
.math-intro-card { display: grid; grid-template-columns: .8fr 1.2fr; overflow: hidden; border: 1px solid var(--line); border-radius: 28px; background: #fff; box-shadow: var(--shadow); min-height: 590px; }
.math-intro-visual { display: grid; grid-template-columns: repeat(2, 115px); place-content: center; gap: 18px; background: radial-gradient(circle at 50% 43%, #fff4bf 0 25%, #dceaa8 26% 64%, #c5dc8a 65%); }
.math-intro-visual span { display: grid; place-items: center; width: 115px; height: 115px; border-radius: 28px; background: #fff; color: var(--green); font-size: 58px; font-weight: 900; box-shadow: 0 12px 28px #234c3722; }
.math-intro-content { padding: 38px 46px; display: flex; flex-direction: column; justify-content: center; }
.math-intro-content h1 { margin: 3px 0 6px; font-size: 42px; line-height: 1.25; }
.math-lead { color: var(--muted); margin: 0 0 16px; font-size: 17px; }
.difficulty-list { display: grid; gap: 10px; margin: 18px 0; }
.difficulty-option { cursor: pointer; display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 10px; text-align: left; padding: 15px 17px; border: 2px solid var(--line); border-radius: 15px; background: #fff; transition: border-color .15s, background .15s, transform .15s; }
.difficulty-option:hover { transform: translateY(-1px); border-color: #a9c2aa; }
.difficulty-option.selected { border-color: var(--green2); background: #edf6eb; box-shadow: 0 0 0 3px #3d8b6214; }
.difficulty-option small { color: var(--green); font-weight: 900; }
.difficulty-option b { font-size: 16px; }
.difficulty-option span { color: var(--muted); font-size: 12px; }
.math-note { display: flex; align-items: flex-start; gap: 9px; border-radius: 12px; background: #fff4dc; padding: 10px 12px; margin: 4px 0 17px; }
.math-note span { flex: none; color: #8d5d14; font-size: 12px; font-weight: 900; }
.math-note p { color: #75572b; margin: 0; font-size: 12px; }
.math-start { align-self: flex-start; min-width: 230px; }
.math-start span { margin-left: 8px; }

.math-play-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 44px; margin-bottom: 10px; }
.math-play-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.math-play-actions .back-button { min-height: 38px; display: inline-flex; align-items: center; padding: 6px 10px; border: 1px solid #cfe2dd; border-radius: 11px; background: #fff; font-size: 13px; text-decoration: none; }
.math-play-top .math-progress { grid-column: 2; color: var(--green); background: #e7f0e5; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 800; }
.math-play-top .difficulty-badge { grid-column: 3; justify-self: end; }
.math-progressbar { height: 8px; overflow: hidden; border-radius: 999px; background: #e4e9e3; margin-bottom: 18px; }
.math-progressbar span { display: block; width: 10%; height: 100%; background: var(--green2); transition: width .25s; }
.math-play-card { width: min(720px, 100%); margin: 0 auto; padding: 26px 34px 30px; border: 1px solid var(--line); border-radius: 28px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.math-score-line { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; font-weight: 800; }
.math-score-line b { color: var(--green); font-size: 19px; }
.equation { display: flex; align-items: center; justify-content: center; gap: clamp(12px, 3vw, 28px); min-height: 180px; font-weight: 900; font-size: clamp(44px, 8vw, 82px); line-height: 1; letter-spacing: -.04em; }
.equation strong { min-width: 120px; color: var(--green); border-bottom: 5px solid #cfe0ce; padding: 0 8px 12px; }
.math-feedback { min-height: 34px; margin: -5px 0 17px; color: var(--muted); font-weight: 800; }
.math-feedback.ok { color: #236748; }
.math-feedback.ng { color: #b55238; }
.math-auto-next { width: min(430px,100%); display: grid; grid-template-columns: auto minmax(80px,1fr) auto; align-items: center; gap: 8px; margin: -8px auto 10px; color: #236748; }
.math-auto-next[hidden] { display: none; }
.math-auto-next small { min-width: 120px; font-weight: 800; }
.math-auto-next button { min-height: 34px; padding: 5px 10px; border: 1px solid currentColor; border-radius: 9px; color: inherit; background: #fff; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }
.math-auto-bar { height: 8px; overflow: hidden; border-radius: 999px; background: #dcebe4; }
.math-auto-bar i { display: block; width: 100%; height: 100%; border-radius: inherit; background: #27845e; transition: width .1s linear; }
.keypad { width: min(390px, 100%); margin: 0 auto 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.keypad button { cursor: pointer; min-height: 64px; border: 1px solid #d7dfd5; border-radius: 13px; background: #f7f8f4; font-size: 25px; font-weight: 900; box-shadow: 0 3px 0 #d7dfd5; }
.keypad button:hover:not(:disabled) { background: #edf4e9; }
.keypad button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #d7dfd5; }
.keypad .key-clear, .keypad .key-back { font-size: 15px; color: var(--muted); }
.keypad button:disabled { opacity: .45; cursor: default; }
.answer-button, .next-button { width: min(390px, 100%); }
.next-button { margin-top: 10px; }

.math-summary { width: min(940px, 100%); margin: 0 auto; }
.math-summary .summary-celebration { margin: 12px 0 20px; }
.math-summary-stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(145deg,#fffdf7,#eff5d8); box-shadow: var(--shadow); overflow: hidden; }
.math-summary-stats > div { text-align: center; padding: 18px 14px; }
.math-summary-stats > div + div { border-left: 1px solid var(--line); }
.math-summary-stats small { display: block; color: var(--muted); font-weight: 800; }
.math-summary-stats b { color: var(--green); font-size: 30px; }
.math-summary-stats span { margin-left: 3px; font-size: 12px; }
.best-result { text-align: center; margin: 14px 0 16px; color: #56675e; font-weight: 800; }
.answer-review { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; margin: 0 0 20px; }
.answer-review > div { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; padding: 11px 7px; border-radius: 13px; background: #f1f4ee; font-size: 11px; color: var(--muted); }
.answer-review > div.correct { background: #eaf3d2; }
.answer-review b { color: var(--ink); font-size: 14px; }
.answer-review i { color: var(--green); font-style: normal; font-weight: 900; }
.math-link-button { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.math-info { width: min(860px, 100%); margin: 70px auto 0; padding: 28px 32px; border-top: 1px solid var(--line); }
.math-info h2 { font-size: 25px; margin: 5px 0 13px; }
.math-info p { color: var(--muted); margin: 8px 0; }
.math-info .medical-note { font-size: 12px; }

.easy-math-game-card .game-icon { background: linear-gradient(135deg, #f8edb5, #d7e9a6); color: var(--green); font-weight: 900; font-size: 42px; }

/* プレイ中は判定と自動進行バーを含めて、現在の画面内に収める。 */
body:has(#play-view:not([hidden])) { overflow: hidden; }
body:has(#play-view:not([hidden])) footer,
.math-page:has(#play-view:not([hidden])) > .math-back,
.math-page:has(#play-view:not([hidden])) > .math-info { display: none; }
.math-page:has(#play-view:not([hidden])) {
  height: calc(100dvh - 82px);
  padding-top: 8px;
  padding-bottom: 8px;
}
.math-page:has(#play-view:not([hidden])) #play-view {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0,1fr);
  overflow: hidden;
}
.math-page:has(#play-view:not([hidden])) .math-play-top { margin-bottom: 5px; }
.math-page:has(#play-view:not([hidden])) .math-progressbar { height: 7px; margin-bottom: 7px; }
.math-page:has(#play-view:not([hidden])) .math-play-card {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 24px 16px;
  overflow: hidden;
}
.math-page:has(#play-view:not([hidden])) .equation { min-height: min(130px,20vh); font-size: clamp(40px,10vh,72px); }
.math-page:has(#play-view:not([hidden])) .math-feedback { min-height: 28px; margin: -3px 0 9px; }
.math-page:has(#play-view:not([hidden])) .keypad { flex: 1; min-height: 0; max-height: 250px; margin-bottom: 9px; }
.math-page:has(#play-view:not([hidden])) .keypad button { min-height: 0; }

@media (max-width: 820px) {
  .math-intro-card { grid-template-columns: 1fr; min-height: 0; }
  .math-intro-visual { min-height: 220px; grid-template-columns: repeat(4, 72px); gap: 9px; }
  .math-intro-visual span { width: 72px; height: 72px; border-radius: 20px; font-size: 38px; }
  .math-intro-content { padding: 26px 24px 30px; }
  .difficulty-option { grid-template-columns: 75px 1fr; }
  .difficulty-option span { grid-column: 2; }
  .math-summary-stats { grid-template-columns: repeat(2, 1fr); }
  .math-summary-stats > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .math-summary-stats > div:nth-child(4) { border-top: 1px solid var(--line); }
  .answer-review { grid-template-columns: repeat(2, 1fr); }
  .summary-actions { flex-direction: column; }
  .summary-actions .button, .summary-actions .math-link-button { width: 100%; }
}
@media (max-width: 600px) {
  .math-header { height: 70px; padding-inline: 14px; }
  .math-header .brand-logo { max-width: 190px; height: 48px; }
  .math-nav a { font-size: 12px; padding: 8px 9px; }
  .math-nav a:last-child { display: none; }
  .math-page { width: min(100% - 24px, 1180px); padding-top: 16px; }
  .math-intro-visual { min-height: 160px; grid-template-columns: repeat(4, 56px); }
  .math-intro-visual span { width: 56px; height: 56px; font-size: 30px; border-radius: 16px; }
  .math-intro-content { padding: 22px 18px 25px; }
  .math-intro-content h1 { font-size: 31px; }
  .math-lead { font-size: 15px; }
  .math-play-top { grid-template-columns: 1fr auto; }
  .math-play-actions { grid-column: 1 / -1; flex-wrap: nowrap; width: 100%; margin-bottom: 4px; }
  .math-play-actions .back-button { flex: 1; justify-content: center; min-height: 34px; margin-bottom: 0; padding: 4px; font-size: 10px; }
  .math-play-top .math-progress { grid-column: 1; justify-self: start; }
  .math-play-top .difficulty-badge { grid-column: 2; }
  .math-play-card { padding: 18px 14px 24px; border-radius: 22px; }
  .equation { min-height: 145px; gap: 10px; font-size: clamp(36px, 13vw, 58px); }
  .equation strong { min-width: 82px; padding-bottom: 9px; border-bottom-width: 4px; }
  .keypad button { min-height: 58px; }
  .math-summary .summary-celebration { align-items: flex-start; }
  .math-summary-stats b { font-size: 25px; }
  .math-info { padding: 24px 5px; margin-top: 52px; }

  .math-page:has(#play-view:not([hidden])) { height: calc(100dvh - 70px); width: calc(100% - 14px); padding: 5px 0; }
  .math-page:has(#play-view:not([hidden])) .math-play-top { min-height: 0; }
  .math-page:has(#play-view:not([hidden])) .math-progressbar { margin-bottom: 4px; }
  .math-page:has(#play-view:not([hidden])) .math-play-card { padding: 9px 8px; border-radius: 18px; }
  .math-page:has(#play-view:not([hidden])) .math-score-line { font-size: 11px; }
  .math-page:has(#play-view:not([hidden])) .math-score-line b { font-size: 15px; }
  .math-page:has(#play-view:not([hidden])) .equation { min-height: min(100px,15vh); font-size: clamp(34px,11vw,52px); }
  .math-page:has(#play-view:not([hidden])) .equation strong { min-width: 70px; padding-bottom: 6px; }
  .math-page:has(#play-view:not([hidden])) .math-feedback { min-height: 24px; margin-bottom: 4px; font-size: 13px; }
  .math-auto-next { grid-template-columns: 1fr auto; gap: 4px; margin: 0 auto 5px; }
  .math-auto-next small { grid-column: 1 / -1; min-width: 0; font-size: 11px; }
  .math-auto-next button { min-height: 29px; }
  .math-page:has(#play-view:not([hidden])) .keypad { max-height: none; margin-bottom: 5px; gap: 5px; }
  .math-page:has(#play-view:not([hidden])) .keypad button { min-height: 0; border-radius: 9px; font-size: 19px; }
  .math-page:has(#play-view:not([hidden])) .answer-button { min-height: 40px; }
}
