/* MATH_WAR_V110 */
.math-war-body {
  background:
    radial-gradient(circle at top left, rgba(120, 210, 255, 0.24), transparent 36vw),
    linear-gradient(180deg, #f5fbff 0%, #edf5ff 100%);
}

.math-war-page {
  display: grid;
  gap: 18px;
}

.math-war-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 22px;
  overflow: hidden;
  position: relative;
}

.math-war-header::after {
  content: "";
  position: absolute;
  inset: auto -30px -80px auto;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  background: rgba(78, 193, 255, 0.16);
  pointer-events: none;
}

.math-war-header-copy {
  position: relative;
  z-index: 1;
  max-width: 800px;
}

.math-war-header h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.08;
}

.math-war-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}

.math-war-header-actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.math-war-shell {
  position: relative;
  overflow: hidden;
  padding: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(244, 249, 255, 0.9));
}

.math-war-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--math-war-bg);
  background-size: cover;
  background-position: center;
  filter: blur(22px);
  transform: scale(1.08);
  opacity: 0.38;
  pointer-events: none;
}

.math-war-topbar,
.math-war-main {
  position: relative;
  z-index: 1;
}

.math-war-topbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(96px, 1fr)) auto;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 12px;
}

.math-war-stat {
  border: 1px solid rgba(184, 195, 226, 0.85);
  border-radius: 18px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 24px rgba(39, 68, 124, 0.08);
}

.math-war-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.math-war-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 1.05rem;
  line-height: 1.2;
}

.math-war-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.math-war-toolbar .is-hidden {
  display: none;
}

.math-war-main {
  display: block;
}

.math-war-canvas-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.38), 0 16px 38px rgba(31, 70, 121, 0.18);
  min-height: 500px;
  touch-action: auto;
}

.math-war-canvas-wrap canvas {
  display: block;
  width: 100%;
  max-height: min(62vh, 700px);
  min-height: 500px;
  background: transparent;
  touch-action: none;
}

.math-war-floating-message {
  display: none !important;
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 7;
  max-width: min(92%, 640px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 32, 64, 0.78);
  color: #fff;
  font-weight: 900;
  text-align: center;
  box-shadow: 0 12px 24px rgba(11, 22, 48, 0.2);
  pointer-events: none;
}

.math-war-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 14px;
  background: linear-gradient(180deg, rgba(9, 18, 44, 0.26), rgba(9, 18, 44, 0.46));
  backdrop-filter: blur(8px);
}

.math-war-overlay.hidden,
.math-war-challenge .hidden,
.math-war-end-card .hidden {
  display: none !important;
}

.math-war-overlay-card,
.math-war-challenge-card {
  width: min(620px, 94vw);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(220, 226, 240, 0.96);
  box-shadow: 0 24px 62px rgba(7, 16, 44, 0.24);
  padding: clamp(20px, 4vw, 34px);
  text-align: center;
}

.math-war-overlay-card h2,
.math-war-challenge-card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 4vw, 2.6rem);
}

.math-war-overlay-card p,
.math-war-overlay-card li,
.math-war-challenge-card p {
  color: var(--muted);
  line-height: 1.7;
}

.math-war-overlay-card ul {
  margin: 16px auto 20px;
  padding-left: 1.2rem;
  text-align: left;
  max-width: 520px;
}

.math-war-challenge-card {
  background:
    radial-gradient(circle at top, rgba(255, 235, 128, 0.36), transparent 34%),
    rgba(255, 255, 255, 0.97);
}

.math-war-challenge-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(91, 108, 240, 0.12);
  color: var(--primary-2);
  font-weight: 900;
}

.math-war-countdown {
  font-size: clamp(6rem, 18vw, 11rem);
  font-weight: 1000;
  line-height: 1;
  color: #fff;
  text-shadow: 0 8px 0 rgba(35, 49, 77, 0.22), 0 20px 42px rgba(47, 79, 148, 0.32);
  -webkit-text-stroke: 6px rgba(91, 108, 240, 0.76);
  paint-order: stroke fill;
  animation: math-war-count-pop 0.82s ease both;
}

@keyframes math-war-count-pop {
  0% { transform: scale(0.62); opacity: 0; }
  28% { transform: scale(1.16); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.math-war-quiz-problem {
  margin: 16px auto;
  border-radius: 24px;
  padding: 18px;
  background: linear-gradient(135deg, #26395f, #4355d8);
  color: #fff;
  font-size: clamp(2.2rem, 8vw, 4.6rem);
  font-weight: 1000;
  letter-spacing: 0.03em;
  box-shadow: inset 0 -8px 18px rgba(0, 0, 0, 0.14), 0 14px 30px rgba(52, 72, 170, 0.22);
}

.math-war-quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.math-war-quiz-option {
  appearance: none;
  border: 0;
  border-radius: 24px;
  padding: 18px 12px;
  color: #fff;
  background: linear-gradient(135deg, #ffae3d, #ff7d4f);
  box-shadow: 0 12px 26px rgba(255, 117, 64, 0.24);
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  font-weight: 1000;
  cursor: pointer;
}

.math-war-quiz-option:nth-child(2) {
  background: linear-gradient(135deg, #39c992, #2ea3ff);
  box-shadow: 0 12px 26px rgba(46, 163, 255, 0.24);
}

.math-war-quiz-option:hover {
  transform: translateY(-2px);
}

.math-war-return-icon {
  font-size: clamp(3.2rem, 10vw, 6rem);
  line-height: 1;
  filter: drop-shadow(0 12px 20px rgba(91, 108, 240, 0.22));
  animation: math-war-return-pulse 0.94s ease infinite alternate;
}

@keyframes math-war-return-pulse {
  from { transform: scale(0.94) rotate(-2deg); }
  to { transform: scale(1.08) rotate(2deg); }
}

.math-war-end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.math-war-end-stats div {
  padding: 14px 10px;
  border-radius: 18px;
  background: #f5f7ff;
}

.math-war-end-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.math-war-end-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 1.5rem;
}

.math-war-clear-bonus {
  margin: 14px 0 18px;
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 215, 85, 0.28), rgba(255, 255, 255, 0.86));
  border: 1px solid rgba(240, 190, 64, 0.45);
}

.math-war-clear-bonus strong,
.math-war-clear-bonus span {
  display: block;
}

.math-war-clear-bonus span {
  margin-top: 4px;
  color: #8b681e;
  line-height: 1.5;
}

.math-war-end-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.math-war-side-panel {
  display: grid;
  gap: 12px;
}

.math-war-side-card {
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(184, 195, 226, 0.82);
  box-shadow: 0 12px 26px rgba(39, 68, 124, 0.08);
}

.math-war-side-card h2 {
  margin: 0 0 10px;
}

.math-war-side-card p,
.math-war-side-card li {
  color: var(--muted);
  line-height: 1.68;
}

.math-war-side-card ol {
  margin: 0;
  padding-left: 1.2rem;
}

.math-war-touch-controls {
  display: none;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.math-war-touch-button {
  appearance: none;
  border: 0;
  min-height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, #5b6cf0, #89a0ff);
  color: #fff;
  font-weight: 1000;
  font-size: 1.25rem;
  box-shadow: 0 12px 24px rgba(91, 108, 240, 0.22);
}

.math-war-touch-wide {
  background: linear-gradient(135deg, #27385f, #4b5f94);
}

@media (max-width: 980px) {
  .math-war-header {
    display: grid;
    padding: 16px;
  }

  .math-war-header-actions {
    justify-content: flex-start;
  }

  .math-war-topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .math-war-toolbar {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .math-war-canvas-wrap,
  .math-war-canvas-wrap canvas {
    min-height: 470px;
  }

  .math-war-canvas-wrap canvas {
    max-height: 66vh;
  }

  .math-war-touch-controls,
  .math-war-sticky-actions {
    display: grid;
  }

  .math-war-sticky-actions {
    grid-template-columns: 1.2fr 1fr;
    position: sticky;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 16;
  }
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100vw - 12px, 1180px);
  }

  .math-war-shell {
    padding: 8px;
  }

  .math-war-topbar {
    gap: 8px;
  }

  .math-war-stat {
    padding: 8px 10px;
    border-radius: 14px;
  }

  .math-war-stat strong {
    font-size: 0.95rem;
  }

  .math-war-canvas-wrap,
  .math-war-canvas-wrap canvas {
    min-height: 420px;
  }

  .math-war-floating-message {
  display: none !important;
    top: 8px;
    font-size: 0.82rem;
    padding: 8px 12px;
  }

  .math-war-quiz-options,
  .math-war-end-stats {
    grid-template-columns: 1fr;
  }
}

.math-war-quiz-option.is-correct {
  outline: 5px solid rgba(90, 238, 147, 0.9);
  filter: saturate(1.18) brightness(1.08);
}

.math-war-quiz-option.is-wrong {
  outline: 5px solid rgba(255, 82, 108, 0.85);
  filter: grayscale(0.18) brightness(0.92);
}


/* MATH_WAR_V60 integrated mobile/game-only adjustments */
.math-war-shell {
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(244,249,255,0.94));
}

.math-war-canvas-wrap {
  width: 100%;
}

.math-war-overlay {
  touch-action: auto;
}

.math-war-overlay-card {
  max-height: calc(100% - 10px);
  overflow: auto;
}

.math-war-start-card {
  max-width: 560px;
}

.math-war-start-points {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
  color: var(--muted);
  font-weight: 700;
}

.math-war-overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.math-war-side-panel {
  display: none !important;
}

.math-war-sticky-actions {
  display: none;
  gap: 10px;
  margin-top: 12px;
}

.math-war-sticky-actions .is-hidden {
  display: none !important;
}

.math-war-canvas-wrap.is-portrait-mobile {
  min-height: 430px;
}

.math-war-canvas-wrap.is-portrait-mobile canvas {
  max-height: 58svh;
  min-height: 420px;
}

@media (max-width: 560px) {
  .math-war-header {
    padding: 12px;
  }

  .math-war-header h1 {
    font-size: clamp(1.8rem, 8vw, 2.6rem);
  }

  .math-war-topbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .math-war-toolbar {
    grid-column: 1 / -1;
  }

  .math-war-overlay-card,
  .math-war-challenge-card {
    margin-top: 6px;
  }
}


.math-war-buddy-picker {
  margin: 10px 0 16px;
  text-align: left;
}

.math-war-buddy-picker h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.math-war-buddy-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.math-war-buddy-card {
  border: 1px solid rgba(181, 194, 229, 0.9);
  border-radius: 16px;
  padding: 12px;
  background: rgba(248, 252, 255, 0.96);
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.math-war-buddy-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(54, 88, 158, 0.12);
}

.math-war-buddy-card.is-selected {
  border-color: rgba(98, 120, 255, 0.96);
  box-shadow: 0 0 0 3px rgba(98, 120, 255, 0.16);
}

.math-war-buddy-thumb {
  width: 60px;
  height: 60px;
  border-radius: 14px;
  background: linear-gradient(180deg, #fff5c9, #ffd983);
  display: grid;
  place-items: center;
  font-size: 1.7rem;
}

.math-war-buddy-meta strong,
.math-war-buddy-meta span {
  display: block;
}

.math-war-buddy-meta span {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

@media (max-width: 760px) {
  .math-war-canvas-wrap,
  .math-war-canvas-wrap canvas {
    min-height: 420px;
  }

  .math-war-canvas-wrap canvas {
    max-height: 54svh;
  }
}


.math-war-start-card {
  max-width: 560px;
  max-height: min(72vh, 620px);
  overflow: auto;
  padding: 22px 20px 20px;
}

.math-war-start-card h2 {
  margin: 6px 0 12px;
  font-size: clamp(2rem, 4.4vw, 2.9rem);
  line-height: 1.18;
}

.math-war-start-copy {
  margin: 10px 0 12px;
  color: var(--muted);
  line-height: 1.65;
}

.math-war-start-points {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 16px;
}

.math-war-start-points span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(240, 246, 255, 0.95);
  border: 1px solid rgba(184, 195, 226, 0.8);
  color: var(--muted);
  font-weight: 800;
  font-size: 0.9rem;
}

.math-war-buddy-picker {
  margin: 2px 0 8px;
  text-align: left;
}

.math-war-buddy-picker h3 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.math-war-buddy-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.math-war-buddy-card {
  padding: 10px 12px;
  grid-template-columns: 56px 1fr;
}

.math-war-buddy-thumb {
  width: 56px;
  height: 56px;
  font-size: 1.55rem;
}

.math-war-buddy-meta strong {
  font-size: 0.98rem;
}

.math-war-buddy-meta span {
  font-size: 0.8rem;
}

@media (max-width: 760px) {
  .math-war-start-card {
    max-height: min(78vh, 620px);
    padding: 18px 14px 16px;
  }

  .math-war-start-card h2 {
    font-size: clamp(1.7rem, 9vw, 2.4rem);
  }
}


/* MATH_WAR_V63: keep canvas aspect ratio to prevent slime distortion. */
.math-war-canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 460px;
}

.math-war-canvas-wrap canvas {
  width: auto;
  max-width: 100%;
  min-height: 0;
  max-height: none;
}

.math-war-start-card {
  max-width: 540px;
  max-height: min(76vh, 640px);
  padding: 18px 18px 18px;
}

.math-war-start-card h2 {
  margin: 4px 0 10px;
  font-size: clamp(1.85rem, 4.2vw, 2.55rem);
  line-height: 1.14;
}

.math-war-buddy-picker {
  margin: 2px 0 8px;
}

.math-war-buddy-list {
  max-height: 176px;
  overflow: auto;
  padding: 2px 3px 2px 2px;
}

.math-war-buddy-card {
  min-height: 58px;
  padding: 8px 10px;
}

.math-war-start-copy {
  margin: 8px 0 10px;
  font-size: 0.94rem;
}

.math-war-start-points {
  margin: 8px 0 14px;
}

.math-war-coop-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(12, 20, 42, 0.42);
  backdrop-filter: blur(8px);
}

.math-war-coop-panel.hidden,
.math-war-coop-controller.hidden,
.math-war-coop-room.hidden,
.math-war-coop-role-hint.hidden {
  display: none !important;
}

.math-war-coop-card {
  width: min(760px, 96vw);
  max-height: min(88vh, 760px);
  overflow: auto;
  padding: 22px;
  border-radius: 24px;
}

.math-war-coop-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.math-war-coop-head h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3.6vw, 2.2rem);
}

.math-war-coop-status,
.math-war-coop-role-hint {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(240, 246, 255, 0.96);
  color: var(--muted);
  line-height: 1.55;
}

.math-war-coop-status.is-error {
  background: rgba(255, 236, 240, 0.98);
  color: #a12f4a;
}

.math-war-coop-steps,
.math-war-coop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.math-war-coop-step-box,
.math-war-coop-box {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(184, 195, 226, 0.85);
  background: rgba(255, 255, 255, 0.92);
}

.math-war-coop-step-box ol {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.55;
}

.math-war-coop-box p {
  color: var(--muted);
  line-height: 1.55;
}

.math-war-coop-room {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.math-war-coop-room strong {
  font-size: 2rem;
  letter-spacing: 0.18em;
  color: var(--primary-2);
}

.math-war-coop-join-row {
  display: flex;
  gap: 8px;
}

.math-war-coop-join-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(184, 195, 226, 0.95);
  border-radius: 14px;
  padding: 12px;
  font-weight: 900;
  font-size: 1.1rem;
}

.math-war-coop-controller {
  margin-top: 14px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(239, 246, 255, 0.96);
  border: 1px solid rgba(152, 177, 255, 0.72);
}

.math-war-coop-controller-title {
  margin: 0 0 10px;
  font-weight: 1000;
}

.math-war-coop-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 760px) {
  .math-war-canvas-wrap {
    min-height: 360px;
  }
  .math-war-coop-steps,
  .math-war-coop-grid,
  .math-war-coop-actions {
    grid-template-columns: 1fr;
  }
  .math-war-coop-card {
    padding: 16px;
  }
}


/* MATH_WAR_V69: 初期画面はゲームフィールド内のクリック開始表示へ寄せる */
.math-war-start-overlay {
  background: linear-gradient(180deg, rgba(4, 12, 32, 0.06), rgba(4, 12, 32, 0.14));
  backdrop-filter: none;
  place-items: center;
  cursor: pointer;
}

.math-war-start-overlay .math-war-start-card {
  width: min(470px, 88%);
  max-height: min(82%, 520px);
  overflow: auto;
  border-radius: 24px;
  padding: 18px 18px 16px;
  background: rgba(255, 255, 255, 0.90);
  box-shadow: 0 18px 44px rgba(7, 16, 44, 0.18);
}

.math-war-start-overlay .math-war-start-card h2 {
  margin: 4px 0 10px;
  font-size: clamp(1.9rem, 4.6vw, 2.7rem);
  line-height: 1.12;
}

.math-war-start-overlay .math-war-start-copy {
  margin: 9px 0 10px;
  line-height: 1.55;
  color: var(--muted);
}

.math-war-start-overlay .math-war-buddy-picker {
  margin: 4px 0 8px;
}

.math-war-start-overlay .math-war-buddy-picker h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

.math-war-start-overlay .math-war-buddy-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  max-height: 148px;
  overflow: auto;
  padding-right: 2px;
}

.math-war-start-overlay .math-war-buddy-card {
  min-height: 58px;
  padding: 8px 10px;
  grid-template-columns: 48px 1fr;
}

.math-war-start-overlay .math-war-buddy-thumb {
  width: 48px;
  height: 48px;
  border-radius: 13px;
}

.math-war-start-overlay .math-war-buddy-meta strong {
  font-size: 0.94rem;
}

.math-war-start-overlay .math-war-buddy-meta span {
  font-size: 0.76rem;
}

.math-war-start-overlay .math-war-start-points {
  margin: 8px 0 12px;
  gap: 6px;
}

.math-war-start-overlay .math-war-start-points span {
  font-size: 0.82rem;
  padding: 5px 9px;
}

.math-war-start-overlay .math-war-overlay-actions {
  gap: 8px;
}

@media (max-width: 760px) {
  .math-war-start-overlay .math-war-start-card {
    width: min(440px, 92%);
    max-height: min(86%, 560px);
    padding: 16px 14px;
  }
  .math-war-start-overlay .math-war-start-card h2 {
    font-size: clamp(1.65rem, 8vw, 2.35rem);
  }
}



/* MATH_WAR_V69: iOS Safari cannot use the Fullscreen API reliably.
   Use a CSS-based mobile play shell so the game is playable without page scrolling. */
@media (max-width: 760px) {
  body.math-war-mobile-lock {
    overflow: hidden !important;
    overscroll-behavior: none;
    background: #eef5ff;
  }

  body.math-war-mobile-lock .page-shell {
    width: 100vw !important;
    max-width: 100vw !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.math-war-mobile-lock .math-war-header {
    display: none !important;
  }

  body.math-war-mobile-lock .math-war-page {
    display: block;
    gap: 0;
  }

  .math-war-shell.math-war-mobile-focus {
    position: fixed;
    inset: 0;
    z-index: 9999;
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    padding: max(4px, env(safe-area-inset-top)) 4px max(4px, env(safe-area-inset-bottom));
    border-radius: 0 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(180deg, #f7fbff, #eef5ff);
  }

  .math-war-mobile-focus .math-war-topbar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    margin: 0 0 4px;
    align-items: stretch;
  }

  .math-war-mobile-focus .math-war-stat {
    min-height: 38px;
    padding: 4px 5px;
    border-radius: 10px;
  }

  .math-war-mobile-focus .math-war-stat span {
    font-size: 0.56rem;
    letter-spacing: 0;
  }

  .math-war-mobile-focus .math-war-stat strong {
    font-size: 0.76rem;
    line-height: 1.08;
    margin-top: 1px;
    white-space: nowrap;
  }

  .math-war-mobile-focus .math-war-toolbar {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.15fr 1fr 1fr 1fr 1fr;
    gap: 4px;
    justify-content: stretch;
  }

  .math-war-mobile-focus .math-war-toolbar .button {
    min-height: 34px;
    padding: 6px 3px;
    border-radius: 999px;
    font-size: 0.72rem;
    line-height: 1.05;
    white-space: nowrap;
  }

  .math-war-mobile-focus .math-war-main {
    flex: 1 1 auto;
    min-height: 0;
    display: block;
  }

  .math-war-mobile-focus .math-war-canvas-wrap {
    height: 100%;
    min-height: 0 !important;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .math-war-mobile-focus .math-war-canvas-wrap canvas {
    min-height: 0 !important;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
  }

  .math-war-mobile-focus .math-war-touch-controls {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: 1fr 1.05fr 1fr;
    gap: 5px;
    margin-top: 4px;
  }

  .math-war-mobile-focus .math-war-touch-button {
    min-height: 40px;
    border-radius: 12px;
    font-size: 1rem;
  }

  .math-war-mobile-focus .math-war-sticky-actions {
    display: none !important;
  }

  .math-war-mobile-focus .math-war-start-overlay {
    padding: 8px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-start-card {
    width: min(92vw, 360px);
    max-height: 92%;
    padding: 12px 12px 10px;
    border-radius: 18px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-start-card .eyebrow {
    font-size: 0.7rem;
    margin-bottom: 2px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-start-card h2 {
    font-size: clamp(1.35rem, 7vw, 1.85rem);
    margin: 2px 0 8px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-picker {
    margin: 0 0 7px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-picker h3 {
    font-size: 0.82rem;
    margin-bottom: 5px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-list {
    max-height: 110px;
    overflow: auto;
    gap: 5px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-card {
    min-height: 46px;
    grid-template-columns: 40px 1fr;
    gap: 7px;
    padding: 6px 8px;
    border-radius: 13px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-thumb {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    font-size: 1.1rem;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-meta strong {
    font-size: 0.82rem;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-buddy-meta span {
    font-size: 0.66rem;
    line-height: 1.22;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-start-copy {
    display: none;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-start-points {
    display: none;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-overlay-actions {
    gap: 6px;
  }

  .math-war-mobile-focus .math-war-start-overlay .math-war-overlay-actions .button {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 0.85rem;
  }

  .math-war-mobile-focus .math-war-challenge-card,
  .math-war-mobile-focus .math-war-end-card {
    width: min(92vw, 380px);
    max-height: 92%;
    overflow: auto;
    padding: 14px 12px;
    border-radius: 18px;
  }

  .math-war-mobile-focus .math-war-quiz-problem {
    font-size: clamp(2rem, 12vw, 3.4rem);
    padding: 12px;
  }

  .math-war-mobile-focus .math-war-quiz-options {
    gap: 8px;
  }

  .math-war-mobile-focus .math-war-quiz-option {
    padding: 12px 8px;
  }
}


/* MATH_WAR_V69: coop buddy movement controls + compact quiz for phones/tablets */
.math-war-coop-move {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0;
}

.math-war-coop-move-button {
  min-height: 52px;
  font-size: 1.05rem;
}

.math-war-challenge-card {
  max-height: min(92vh, 720px);
  overflow: auto;
}

@media (max-width: 900px), (pointer: coarse) {
  .math-war-challenge {
    position: fixed;
    inset: 0;
    z-index: 10020;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    place-items: center;
  }

  .math-war-challenge-card {
    width: min(94vw, 520px);
    max-height: calc(100dvh - 18px);
    padding: 14px 12px;
    border-radius: 18px;
    overflow: auto;
  }

  .math-war-challenge-kicker {
    margin-bottom: 8px;
    padding: 6px 10px;
    font-size: 0.84rem;
  }

  .math-war-challenge-card h2 {
    margin: 0 0 4px;
    font-size: clamp(1.15rem, 5.4vw, 1.7rem);
  }

  .math-war-challenge-card p {
    margin: 4px 0;
    line-height: 1.35;
    font-size: 0.88rem;
  }

  .math-war-quiz-problem {
    margin: 8px auto;
    padding: 10px;
    border-radius: 16px;
    font-size: clamp(2rem, 11vw, 3.2rem);
  }

  .math-war-quiz-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 8px;
  }

  .math-war-quiz-option {
    min-height: 58px;
    padding: 10px 6px;
    border-radius: 16px;
    font-size: clamp(1.7rem, 9vw, 2.7rem);
  }

  .math-war-coop-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-height: 620px) and (pointer: coarse) {
  .math-war-challenge-card {
    max-height: calc(100dvh - 10px);
    padding: 10px 8px;
  }

  .math-war-quiz-problem {
    font-size: clamp(1.8rem, 9vw, 2.8rem);
    margin: 6px auto;
  }

  .math-war-quiz-option {
    min-height: 50px;
    font-size: clamp(1.45rem, 8vw, 2.3rem);
  }
}


/* MATH_WAR_V78: tablet/PC compact layout + emergency bomb button. */
.math-war-bomb-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0 !important;
  border-radius: 12px !important;
  display: inline-grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
}

.math-war-bomb-button:disabled {
  opacity: 0.46;
  filter: grayscale(0.35);
}

@media (min-width: 760px) {
  .math-war-header {
    padding: 12px 18px;
    gap: 12px;
    min-height: 0;
  }

  .math-war-header h1 {
    margin: 0;
    font-size: clamp(1.9rem, 3.05vw, 2.75rem);
    line-height: 1;
  }

  .math-war-header .eyebrow {
    margin-bottom: 4px;
    font-size: 0.78rem;
  }

  .math-war-header::after {
    width: 160px;
    height: 160px;
    inset: auto -22px -66px auto;
  }

  .math-war-header-actions {
    align-items: center;
    gap: 7px;
  }

  .math-war-shell {
    padding-top: 10px;
  }

  .math-war-challenge-card {
    width: min(560px, 64vw);
    max-height: min(84vh, 620px);
    padding: 16px 18px 18px;
  }

  .math-war-challenge-kicker,
  #mathWarQuizTitle,
  #mathWarQuizLead {
    display: none !important;
  }

  .math-war-quiz-problem {
    margin: 0 auto 12px;
    padding: 16px 18px;
    border-radius: 20px;
    font-size: clamp(2.6rem, 5.6vw, 4.8rem);
  }

  .math-war-quiz-options {
    margin-top: 10px;
    gap: 12px;
  }

  .math-war-quiz-option {
    min-height: 82px;
    padding: 12px 8px;
    border-radius: 20px;
    font-size: clamp(2.1rem, 4.2vw, 3.4rem);
  }
}

@media (min-width: 760px) and (max-width: 1100px) {
  .math-war-challenge-card {
    width: min(520px, 76vw);
  }

  .math-war-header {
    padding: 10px 14px;
  }

  .math-war-header h1 {
    font-size: clamp(1.75rem, 3.6vw, 2.4rem);
  }
}


/* MATH_WAR_V110 */
.math-war-end-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(243,247,255,0.98)), radial-gradient(circle at top center, rgba(255,222,120,0.26), rgba(255,255,255,0) 48%);
}
.math-war-clear-choice-box {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 12px 0 8px;
}
.math-war-clear-choice-box.hidden {
  display: none !important;
}
.math-war-clear-choice-box .button {
  width: 100%;
  justify-content: center;
}
.math-war-clear-bonus {
  background: rgba(245, 249, 255, 0.95);
}

/* MATH_WAR_V110 */


/* MATH_WAR_V110 */
.math-war-clear-choice-box .button {
  align-items: stretch;
  padding: 0;
  overflow: hidden;
}
.math-war-reward-choice {
  width: 100%;
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  align-items: center;
  text-align: left;
  padding: 12px 14px;
}
.math-war-reward-thumb {
  width: 88px;
  height: 88px;
  border-radius: 18px;
  position: relative;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.38);
}
.math-war-reward-thumb.is-weapon { background: linear-gradient(180deg, #ffe2ab, #f7b154); }
.math-war-reward-thumb.is-army { background: linear-gradient(180deg, #c7efff, #62b6ff); }
.math-war-reward-thumb-inner { font-size: 2rem; transform: translateY(-6px); }
.math-war-reward-chest { position: absolute; right: 8px; bottom: 6px; font-size: 1.5rem; }
.math-war-reward-copy { display: grid; gap: 4px; min-width: 0; }
.math-war-reward-copy strong { font-size: 1rem; line-height: 1.2; }
.math-war-reward-copy span { font-size: 0.96rem; line-height: 1.35; }
.math-war-reward-copy small { font-size: 0.82rem; color: var(--muted); line-height: 1.35; }
@media (max-width: 560px) {
  .math-war-reward-choice { grid-template-columns: 72px 1fr; gap: 10px; padding: 10px 12px; }
  .math-war-reward-thumb { width: 72px; height: 72px; border-radius: 16px; }
  .math-war-reward-thumb-inner { font-size: 1.7rem; }
  .math-war-reward-chest { font-size: 1.3rem; }
}


/* MATH_WAR_V110 */
.math-war-buddy-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.math-war-buddy-thumb span {
  font-size: 1.7rem;
}


/* MATH_WAR_V110 */
.math-war-end-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.90), rgba(245,248,255,0.92)), url('/static/assets/backgrounds/math_war_reward_room_v109.jpg') center/cover no-repeat !important;
}

.math-war-clear-bonus {
  background: rgba(255,255,255,0.82) !important;
  backdrop-filter: blur(2px);
}

.math-war-reward-choice {
  grid-template-columns: 112px 1fr !important;
  gap: 14px !important;
}

.math-war-reward-thumb {
  width: 104px !important;
  height: 104px !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.math-war-reward-thumb.is-weapon,
.math-war-reward-thumb.is-army {
  background: transparent !important;
}

.math-war-reward-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.16));
}

.math-war-reward-thumb-inner,
.math-war-reward-chest {
  display: none !important;
}

@media (max-width: 560px) {
  .math-war-reward-choice {
    grid-template-columns: 86px 1fr !important;
  }
  .math-war-reward-thumb {
    width: 86px !important;
    height: 86px !important;
  }
}


/* MATH_WAR_V110 */
.math-war-return-icon[data-mode="image"] {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(84px, 18vw, 128px);
  font-size: 0;
}

.math-war-return-icon[data-mode="image"] img {
  display: block;
  width: clamp(120px, 24vw, 220px);
  max-width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(34, 50, 120, 0.22));
}


/* SOURCE_SYNC_MATH_WAR_MODAL_V7: バディ選択が小画面で下まで触れるようにする。 */
.math-war-start-overlay {
  position: fixed !important;
  inset: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  touch-action: pan-y !important;
  overscroll-behavior: contain;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important;
}
.math-war-start-overlay.hidden { display: none !important; }
.math-war-start-overlay .math-war-start-card,
.math-war-overlay-card.math-war-start-card {
  width: min(560px, calc(100vw - 28px)) !important;
  max-width: calc(100vw - 28px) !important;
  max-height: calc(100dvh - 28px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  margin: auto !important;
}
.math-war-start-overlay .math-war-buddy-list {
  max-height: clamp(140px, 34dvh, 320px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
}
.math-war-start-overlay .math-war-overlay-actions {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding-top: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,.96) 35%, rgba(255,255,255,.99));
}
.math-war-coop-panel { overflow-y: auto !important; touch-action: pan-y !important; }
.math-war-coop-card { max-height: calc(100dvh - 28px) !important; overflow-y: auto !important; -webkit-overflow-scrolling: touch; }
@media (max-height: 760px), (max-width: 820px) {
  .math-war-start-overlay { place-items: start center !important; }
  .math-war-start-overlay .math-war-start-card { padding: 14px 14px 12px !important; }
  .math-war-start-overlay .math-war-start-copy { font-size: .86rem !important; line-height: 1.45 !important; margin: 7px 0 8px !important; }
  .math-war-start-overlay .math-war-start-points { display:flex !important; flex-wrap:wrap !important; gap:6px !important; margin:6px 0 8px !important; }
  .math-war-start-overlay .math-war-buddy-list { max-height: clamp(132px, 31dvh, 240px) !important; }
}


/* MATH_WAR_VIEWPORT_FIT_V8: desktop compact fit so the full field/player remains visible. */
@media (min-width: 761px) {
  .math-war-page {
    gap: 10px !important;
  }
  .math-war-header {
    padding: 14px 18px !important;
    align-items: center !important;
  }
  .math-war-header h1 {
    font-size: clamp(2rem, 3.15vw, 2.9rem) !important;
    margin-bottom: 0 !important;
  }
  .math-war-header .eyebrow {
    margin-bottom: 4px !important;
  }
  .math-war-header-actions .button {
    min-height: 42px !important;
    padding: 8px 16px !important;
  }
  .math-war-shell {
    padding: 10px !important;
    overflow: hidden !important;
  }
  .math-war-topbar {
    gap: 8px !important;
    margin-bottom: 8px !important;
  }
  .math-war-stat {
    padding: 8px 10px !important;
    border-radius: 16px !important;
  }
  .math-war-stat strong {
    font-size: 0.98rem !important;
  }
  .math-war-toolbar .button {
    min-height: 38px !important;
    padding: 7px 12px !important;
  }
  .math-war-canvas-wrap {
    min-height: 0 !important;
    height: auto !important;
    align-items: center !important;
    justify-content: center !important;
  }
  .math-war-canvas-wrap canvas {
    min-height: 0 !important;
    max-width: 100% !important;
    height: auto;
  }
}

@media (min-width: 761px) and (max-height: 880px) {
  .math-war-header {
    padding: 10px 16px !important;
  }
  .math-war-header h1 {
    font-size: clamp(1.8rem, 2.8vw, 2.45rem) !important;
  }
  .math-war-header-actions .button {
    min-height: 36px !important;
    padding: 6px 14px !important;
  }
  .math-war-topbar {
    grid-template-columns: repeat(5, minmax(90px, 1fr)) auto !important;
  }
  .math-war-stat {
    padding: 7px 9px !important;
  }
  .math-war-stat span {
    font-size: 0.72rem !important;
  }
  .math-war-stat strong {
    font-size: 0.92rem !important;
  }
  .math-war-toolbar .button {
    min-height: 34px !important;
    padding: 6px 10px !important;
  }
}


/* MATH_WAR_VIEWPORT_FIT_V9: keep the full play field and bottom player visible on desktop/tablet. */
@media (min-width: 761px) {
  .math-war-page {
    gap: 8px !important;
  }
  .math-war-header {
    padding: 10px 16px !important;
    align-items: center !important;
  }
  .math-war-header h1 {
    font-size: clamp(1.75rem, 2.75vw, 2.55rem) !important;
    margin: 0 !important;
    line-height: 1.05 !important;
  }
  .math-war-header .eyebrow {
    margin-bottom: 3px !important;
  }
  .math-war-header-actions {
    gap: 8px !important;
  }
  .math-war-header-actions .button {
    min-height: 36px !important;
    padding: 6px 14px !important;
  }
  .math-war-shell {
    padding: 8px 10px !important;
    overflow: hidden !important;
  }
  .math-war-topbar {
    gap: 8px !important;
    margin-bottom: 6px !important;
    align-items: center !important;
  }
  .math-war-stat {
    padding: 7px 9px !important;
    border-radius: 16px !important;
    min-height: 58px !important;
  }
  .math-war-stat span {
    font-size: 0.72rem !important;
  }
  .math-war-stat strong {
    font-size: 0.92rem !important;
  }
  .math-war-toolbar {
    gap: 7px !important;
  }
  .math-war-toolbar .button {
    min-height: 34px !important;
    padding: 6px 10px !important;
  }
  .math-war-main {
    min-height: 0 !important;
  }
  .math-war-canvas-wrap {
    min-height: 0 !important;
    height: auto !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
  }
  .math-war-canvas-wrap canvas {
    min-height: 0 !important;
    max-width: 100% !important;
    height: auto;
    display: block !important;
  }
}

@media (min-width: 761px) and (max-height: 900px) {
  .math-war-header {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }
  .math-war-topbar {
    grid-template-columns: repeat(5, minmax(86px, 1fr)) auto !important;
  }
  .math-war-stat {
    min-height: 52px !important;
    padding: 6px 8px !important;
  }
  .math-war-shell {
    padding-top: 7px !important;
    padding-bottom: 7px !important;
  }
}

@media (min-width: 761px) and (max-height: 760px) {
  .math-war-header h1 {
    font-size: clamp(1.55rem, 2.45vw, 2.15rem) !important;
  }
  .math-war-header-actions .button,
  .math-war-toolbar .button {
    min-height: 30px !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
  }
  .math-war-stat {
    min-height: 46px !important;
  }
}


/* MATH_WAR_VIEWPORT_FIT_V10: compact layout and keep the bottom player visible. */
@media (min-width: 761px) {
  .math-war-page {
    gap: 7px !important;
  }
  .math-war-header {
    padding: 8px 14px !important;
    align-items: center !important;
  }
  .math-war-header h1 {
    font-size: clamp(1.65rem, 2.6vw, 2.35rem) !important;
    margin: 0 !important;
    line-height: 1.04 !important;
  }
  .math-war-header .eyebrow {
    margin-bottom: 2px !important;
  }
  .math-war-header-actions {
    gap: 7px !important;
  }
  .math-war-header-actions .button {
    min-height: 34px !important;
    padding: 5px 12px !important;
  }
  .math-war-shell {
    padding: 7px 9px !important;
    overflow: hidden !important;
  }
  .math-war-topbar {
    gap: 7px !important;
    margin-bottom: 5px !important;
    align-items: center !important;
  }
  .math-war-stat {
    padding: 6px 8px !important;
    border-radius: 15px !important;
    min-height: 50px !important;
  }
  .math-war-stat span {
    font-size: 0.7rem !important;
  }
  .math-war-stat strong {
    margin-top: 2px !important;
    font-size: 0.9rem !important;
  }
  .math-war-toolbar {
    gap: 6px !important;
  }
  .math-war-toolbar .button {
    min-height: 31px !important;
    padding: 5px 9px !important;
  }
  .math-war-main {
    min-height: 0 !important;
  }
  .math-war-canvas-wrap {
    min-height: 0 !important;
    height: auto !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
  }
  .math-war-canvas-wrap canvas {
    min-height: 0 !important;
    max-width: 100% !important;
    max-height: none !important;
    height: auto;
    display: block !important;
    margin: 0 auto !important;
  }
}

@media (min-width: 761px) and (max-height: 900px) {
  .math-war-header {
    padding-top: 7px !important;
    padding-bottom: 7px !important;
  }
  .math-war-topbar {
    grid-template-columns: repeat(5, minmax(82px, 1fr)) auto !important;
  }
  .math-war-stat {
    min-height: 46px !important;
    padding: 5px 7px !important;
  }
  .math-war-shell {
    padding-top: 6px !important;
    padding-bottom: 6px !important;
  }
}

@media (min-width: 761px) and (max-height: 760px) {
  .math-war-header h1 {
    font-size: clamp(1.45rem, 2.35vw, 2.05rem) !important;
  }
  .math-war-header-actions .button,
  .math-war-toolbar .button {
    min-height: 28px !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
  }
  .math-war-stat {
    min-height: 42px !important;
  }
}
