:root {
  --bg: #f8f4ec;
  --paper: #fffdf8;
  --ink: #33445b;
  --muted: #728096;
  --blue: #6ea9cc;
  --blue-deep: #4f8fb7;
  --blue-soft: #dfeef6;
  --orange: #e99a68;
  --orange-deep: #d9804c;
  --orange-soft: #f8e5d6;
  --yellow-soft: #f6edc9;
  --green: #70ad91;
  --green-soft: #dff0e7;
  --coral: #d9766e;
  --coral-soft: #f7dfdc;
  --lavender-soft: #eee6f2;
  --shadow: 0 18px 48px rgba(81, 94, 112, 0.14);
  --shadow-soft: 0 8px 22px rgba(81, 94, 112, 0.11);
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
  font-family: "Hiragino Sans", "Yu Gothic", "YuGothic", "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100svh;
  min-height: 100dvh;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid rgba(79, 143, 183, 0.34);
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
}

.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(1px);
  opacity: 0.62;
  pointer-events: none;
}

.ambient-a {
  width: min(42vw, 540px);
  aspect-ratio: 1;
  left: -16vw;
  top: -14vw;
  background: #dcebf2;
}

.ambient-b {
  width: min(34vw, 430px);
  aspect-ratio: 1;
  right: -10vw;
  bottom: -13vw;
  background: #f5dfcf;
}

.ambient-c {
  width: min(18vw, 240px);
  aspect-ratio: 1;
  right: 6vw;
  top: 10vh;
  background: #eee4c9;
  opacity: 0.38;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100svh;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  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));
}

.screen {
  display: none;
  width: 100%;
  height: 100%;
}

.screen.is-active {
  display: flex;
}

/* ---------- Start ---------- */
.start-screen {
  align-items: center;
  justify-content: center;
  padding: clamp(4px, 2vh, 20px);
}

.start-card {
  position: relative;
  width: min(100%, 720px);
  max-height: 100%;
  padding: clamp(18px, 4vh, 40px) clamp(16px, 5vw, 48px);
  border: 1px solid rgba(86, 114, 135, 0.08);
  border-radius: var(--radius-xl);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  text-align: center;
  overflow: hidden;
}

.brand-mark {
  position: relative;
  width: clamp(62px, 10vh, 86px);
  height: clamp(62px, 10vh, 86px);
  margin: 0 auto clamp(8px, 1.6vh, 14px);
  border-radius: 28px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--blue-soft), #f5ebda);
  transform: rotate(-3deg);
}

.brand-plus {
  font-size: clamp(40px, 7vh, 58px);
  line-height: 1;
  font-weight: 900;
  color: var(--blue-deep);
  transform: rotate(3deg);
}

.brand-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-one { right: -8px; top: 9px; background: #efaa7e; }
.dot-two { left: -10px; bottom: 14px; background: #e6cb75; }
.dot-three { right: -15px; bottom: -5px; background: #8fc4aa; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--orange-deep);
  font-weight: 800;
  font-size: clamp(12px, 1.8vh, 15px);
  letter-spacing: 0.08em;
}

.start-header h1 {
  margin: 0;
  font-size: clamp(30px, 6vh, 48px);
  line-height: 1.12;
  letter-spacing: 0.04em;
}

.start-lead {
  margin: clamp(5px, 1vh, 10px) 0 clamp(12px, 2.3vh, 22px);
  color: var(--muted);
  font-weight: 700;
  font-size: clamp(14px, 2.2vh, 18px);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 12px);
}

.level-card {
  position: relative;
  min-height: clamp(74px, 12vh, 98px);
  padding: 10px 4px 9px;
  border: 3px solid transparent;
  border-radius: 21px;
  background: #f5f2eb;
  box-shadow: inset 0 0 0 1px rgba(75, 93, 112, 0.04);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.level-card:nth-child(1), .sheet-levels button:nth-child(1) { background: #e5f0f5; }
.level-card:nth-child(2), .sheet-levels button:nth-child(2) { background: #f7e5d8; }
.level-card:nth-child(3), .sheet-levels button:nth-child(3) { background: #f4eccb; }
.level-card:nth-child(4), .sheet-levels button:nth-child(4) { background: #e1eee8; }
.level-card:nth-child(5), .sheet-levels button:nth-child(5) { background: #eee5ef; }

.level-card:active {
  transform: scale(0.96);
}

.level-card.is-selected {
  border-color: var(--blue-deep);
  box-shadow: 0 7px 16px rgba(79, 143, 183, 0.16);
  transform: translateY(-3px);
}

.level-card.is-selected::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-deep);
  color: white;
  font-size: 13px;
  font-weight: 900;
}

.level-number {
  display: block;
  font-size: clamp(27px, 4vh, 34px);
  line-height: 1;
  font-weight: 900;
}

.level-label {
  display: block;
  margin-top: 6px;
  font-size: clamp(11px, 1.7vh, 14px);
  font-weight: 800;
  color: #657489;
}

.start-button {
  width: min(100%, 390px);
  min-height: clamp(58px, 8.6vh, 70px);
  margin-top: clamp(14px, 2.5vh, 24px);
  padding: 0 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #efad80, var(--orange));
  box-shadow: 0 8px 0 #d88351, 0 13px 25px rgba(198, 118, 68, 0.18);
  color: #fffdf9;
  font-size: clamp(19px, 3vh, 24px);
  font-weight: 900;
  letter-spacing: 0.05em;
  transition: transform 100ms ease, box-shadow 100ms ease;
}

.start-button:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #d88351, 0 7px 16px rgba(198, 118, 68, 0.15);
}

.start-arrow {
  display: inline-block;
  margin-left: 12px;
  font-size: 1.35em;
  vertical-align: -0.06em;
}

/* ---------- Game ---------- */
.game-screen {
  flex-direction: column;
  gap: clamp(8px, 1.5vh, 14px);
}

.game-header {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  height: clamp(48px, 7.5vh, 64px);
  flex: 0 0 auto;
}

.status-pill,
.score-pill {
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.93);
  border: 1px solid rgba(75, 95, 115, 0.08);
  box-shadow: var(--shadow-soft);
}

.status-pill {
  min-width: 112px;
  padding: 7px 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.status-pill:active {
  transform: scale(0.98);
}

.status-pill strong {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border-radius: 12px;
  background: var(--blue-soft);
  color: var(--blue-deep);
  font-size: 22px;
  line-height: 1;
}

.tiny-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.score-pill {
  min-width: 142px;
  padding: 6px 16px 6px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transform-origin: center;
}

.score-star {
  color: #d9b24e;
  font-size: 26px;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(149, 112, 34, 0.12);
}

.score-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}

.score-copy strong {
  margin-top: 3px;
  font-size: clamp(20px, 3.4vh, 28px);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.score-unit {
  align-self: flex-end;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.game-main {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(8px, 1.5vh, 14px);
}

.problem-card {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(12px, 2.1vh, 20px);
  padding: clamp(16px, 3vh, 32px) 16px;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: rgba(255, 253, 248, 0.95);
  border: 1px solid rgba(80, 99, 119, 0.08);
  box-shadow: var(--shadow);
}

.problem-card::before,
.problem-card::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  opacity: 0.5;
  pointer-events: none;
}

.problem-card::before {
  width: 120px;
  height: 120px;
  background: var(--blue-soft);
  left: -55px;
  top: -52px;
}

.problem-card::after {
  width: 90px;
  height: 90px;
  background: var(--orange-soft);
  right: -42px;
  bottom: -32px;
}

.problem-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: clamp(7px, 2.6vw, 22px);
  line-height: 1;
  white-space: nowrap;
}

.operand {
  min-width: 0.9ch;
  text-align: center;
  font-size: clamp(60px, min(15.5vw, 11.8vh), 124px);
  font-weight: 900;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}

.operator {
  color: var(--orange-deep);
  font-size: clamp(44px, min(10vw, 8.6vh), 82px);
  font-weight: 800;
}

.equals {
  color: var(--blue-deep);
  font-size: clamp(40px, min(9vw, 7.8vh), 74px);
  font-weight: 800;
}

.answer-zone {
  position: relative;
  z-index: 1;
}

.answer-display {
  position: relative;
  min-width: clamp(138px, 35vw, 260px);
  min-height: clamp(78px, 12.5vh, 108px);
  padding: 5px 22px;
  display: grid;
  place-items: center;
  border: 4px solid #bad8e8;
  border-radius: 25px;
  background: #f7fbfd;
  color: var(--ink);
  box-shadow: inset 0 -4px 0 rgba(74, 125, 157, 0.07);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.answer-text {
  font-size: clamp(52px, min(13vw, 8.8vh), 78px);
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.answer-display.is-empty .answer-text {
  color: #a9c6d6;
}

.answer-display.is-correct {
  border-color: #8fc5aa;
  background: var(--green-soft);
  color: #4c8e70;
  transform: scale(1.045);
}

.answer-display.is-wrong {
  border-color: #e7a29c;
  background: #fff9f8;
}

.answer-display.is-revealed {
  border-color: #dc8a82;
  background: var(--coral-soft);
  color: #bd5d55;
}

.answer-caret {
  position: absolute;
  bottom: 10px;
  width: 28%;
  height: 4px;
  border-radius: 999px;
  background: #c6dbe6;
  opacity: 0;
}

.answer-display.is-empty .answer-caret {
  opacity: 0.7;
}

.correct-circle {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  color: rgba(78, 161, 116, 0.92);
  font-family: system-ui, sans-serif;
  font-size: clamp(128px, 34vw, 250px);
  font-weight: 400;
  line-height: 0.8;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.35) rotate(-8deg);
}

.correct-circle.is-showing {
  animation: circle-pop 720ms cubic-bezier(0.18, 0.83, 0.3, 1) both;
}

.feedback-slot {
  position: relative;
  z-index: 2;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.feedback {
  margin: 0;
  color: var(--muted);
  font-size: clamp(17px, 2.6vh, 22px);
  font-weight: 800;
  text-align: center;
  line-height: 1.25;
}

.feedback:empty {
  min-width: 1px;
}

.feedback.is-correct { color: #568f73; }
.feedback.is-wrong { color: #bf6e67; }
.feedback.is-revealed { color: #bd5d55; }
.feedback.is-nudge { animation: nudge 380ms ease; }

.skip-button {
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 13px;
  background: var(--coral-soft);
  color: #b75f58;
  font-size: 14px;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(175, 91, 84, 0.08);
}

.skip-button:active { transform: scale(0.96); }

.controls {
  width: min(100%, 660px);
  margin: 0 auto;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 1.3vh, 12px);
}

.number-key {
  min-height: clamp(60px, 8.9vh, 78px);
  border-radius: clamp(18px, 2.5vh, 24px);
  background: rgba(255, 253, 248, 0.97);
  border: 1px solid rgba(75, 95, 115, 0.08);
  box-shadow: 0 5px 0 rgba(83, 105, 124, 0.11), 0 8px 18px rgba(72, 90, 109, 0.08);
  font-size: clamp(28px, 5vh, 40px);
  font-weight: 900;
  line-height: 1;
  transition: transform 80ms ease, box-shadow 80ms ease, background 120ms ease;
}

.number-key:nth-child(3n + 1) { background: #f7fbfd; }
.number-key:nth-child(3n + 2) { background: #fffaf6; }
.number-key:nth-child(3n + 3) { background: #fcfaf2; }

.number-key:active:not(:disabled) {
  transform: translateY(4px) scale(0.99);
  box-shadow: 0 1px 0 rgba(83, 105, 124, 0.1), 0 3px 8px rgba(72, 90, 109, 0.06);
}

.number-key:disabled,
.answer-button:disabled {
  opacity: 0.76;
}

.delete-key {
  grid-column: span 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: #edf4f6 !important;
  color: #688397;
  font-size: clamp(21px, 3.8vh, 29px);
}

.delete-label {
  font-size: 0.48em;
  font-weight: 900;
}

.zero-key {
  background: #fff8f2 !important;
}

.answer-button {
  width: 100%;
  min-height: clamp(64px, 9.5vh, 80px);
  margin-top: clamp(10px, 1.4vh, 14px);
  border-radius: 24px;
  background: linear-gradient(180deg, #7eb5d2, var(--blue));
  box-shadow: 0 6px 0 #518eaf, 0 11px 24px rgba(73, 132, 167, 0.18);
  color: white;
  font-size: clamp(24px, 3.5vh, 30px);
  font-weight: 900;
  letter-spacing: 0.07em;
  transition: transform 90ms ease, box-shadow 90ms ease;
}

.answer-button:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #518eaf, 0 5px 13px rgba(73, 132, 167, 0.15);
}

/* ---------- Level sheet ---------- */
.level-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(53, 67, 82, 0.25);
  opacity: 0;
  transition: opacity 180ms ease;
}

.sheet-panel {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(calc(100% - 20px), 620px);
  padding: 12px 16px 16px;
  border-radius: 28px;
  background: #fffdf9;
  box-shadow: 0 24px 70px rgba(47, 61, 76, 0.24);
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 24px) scale(0.98);
  transition: opacity 180ms ease, transform 180ms ease;
}

.level-sheet.is-open .sheet-backdrop { opacity: 1; }
.level-sheet.is-open .sheet-panel { opacity: 1; transform: translate(-50%, 0) scale(1); }

.sheet-handle {
  width: 54px;
  height: 5px;
  margin: 0 auto 8px;
  border-radius: 999px;
  background: #d7dce1;
}

.sheet-panel h2 {
  margin: 0;
  font-size: 24px;
}

.sheet-panel > p {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.sheet-levels {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.sheet-levels button {
  min-height: 68px;
  padding: 7px 3px;
  border: 3px solid transparent;
  border-radius: 18px;
}

.sheet-levels button.is-selected {
  border-color: var(--blue-deep);
}

.sheet-levels strong,
.sheet-levels span { display: block; }
.sheet-levels strong { font-size: 26px; line-height: 1; }
.sheet-levels span { margin-top: 5px; font-size: 11px; font-weight: 800; color: var(--muted); }

.sheet-close {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border-radius: 16px;
  background: #eef1f2;
  color: #657386;
  font-weight: 900;
}

.celebration-burst {
  position: absolute;
  left: 50%;
  top: clamp(72px, 12vh, 110px);
  z-index: 24;
  pointer-events: none;
  transform: translate(-50%, -10px);
  opacity: 0;
}

.celebration-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 11px 20px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid rgba(95, 118, 138, 0.09);
  box-shadow: 0 12px 30px rgba(76, 94, 112, 0.16);
}

.celebration-emoji {
  font-size: clamp(24px, 4.4vw, 34px);
  line-height: 1;
}

.celebration-text {
  margin: 0;
  color: var(--orange-deep);
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.03em;
}

.celebration-burst.is-showing {
  animation: celebrate-pop 980ms cubic-bezier(0.2, 0.88, 0.25, 1) both;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

/* ---------- Motion ---------- */
@keyframes circle-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.35) rotate(-8deg); }
  34% { opacity: 0.95; transform: translate(-50%, -50%) scale(1.12) rotate(3deg); }
  72% { opacity: 0.82; transform: translate(-50%, -50%) scale(0.98) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.03) rotate(0deg); }
}

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

@keyframes card-correct {
  0%, 100% { transform: scale(1); }
  48% { transform: scale(1.012); }
}

@keyframes score-pop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1) rotate(1.5deg); }
}

@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes soft-bump {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

.problem-card.is-wrong { animation: wrong-shake 330ms ease; }
.problem-card.is-correct { animation: card-correct 780ms ease; }
.score-pop { animation: score-pop 420ms ease; }
.soft-bump { animation: soft-bump 220ms ease; }

@keyframes celebrate-pop {
  0% { opacity: 0; transform: translate(-50%, -10px) scale(0.78); }
  20% { opacity: 1; transform: translate(-50%, -22px) scale(1.08) rotate(-2deg); }
  56% { opacity: 1; transform: translate(-50%, -26px) scale(1) rotate(1deg); }
  100% { opacity: 0; transform: translate(-50%, -36px) scale(0.96); }
}

/* ---------- Phone ---------- */
@media (max-width: 560px) {
  .app-shell { padding: max(8px, env(safe-area-inset-top)) max(9px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left)); }
  .start-card { border-radius: 26px; }
  .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .level-card { min-height: 68px; }
  .level-card:nth-child(4) { grid-column: 1 / 2; }
  .level-card:nth-child(5) { grid-column: 2 / 3; }
  .game-header { height: 56px; }
  .status-pill { min-width: 102px; padding: 6px 12px; }
  .status-pill .tiny-label { display: none; }
  .status-pill strong { width: 34px; height: 34px; }
  .score-pill { min-width: 126px; padding-right: 12px; }
  .score-star { font-size: 22px; }
  .problem-card { border-radius: 26px; }
  .celebration-chip { min-height: 48px; padding: 9px 16px; }
  .celebration-text { font-size: 22px; }
}

/* ---------- Short phones ---------- */
@media (max-height: 690px) and (orientation: portrait) {
  .start-card { padding-top: 14px; padding-bottom: 14px; }
  .brand-mark { width: 54px; height: 54px; border-radius: 20px; margin-bottom: 5px; }
  .brand-plus { font-size: 37px; }
  .start-header h1 { font-size: 29px; }
  .start-lead { margin: 4px 0 10px; }
  .level-card { min-height: 60px; padding: 7px 3px; border-radius: 17px; }
  .level-number { font-size: 25px; }
  .level-label { margin-top: 3px; font-size: 10px; }
  .start-button { min-height: 52px; margin-top: 12px; border-radius: 18px; font-size: 19px; }
  .game-screen { gap: 7px; }
  .game-header { height: 46px; }
  .status-pill, .score-pill { border-radius: 15px; }
  .status-pill strong { width: 31px; height: 31px; font-size: 20px; }
  .score-copy strong { font-size: 20px; }
  .problem-card { gap: 7px; padding: 9px 12px; }
  .operand { font-size: clamp(49px, 12.8vw, 62px); }
  .operator, .equals { font-size: 40px; }
  .answer-display { min-height: 60px; min-width: 122px; border-radius: 21px; }
  .answer-text { font-size: 43px; }
  .feedback-slot { min-height: 31px; }
  .feedback { font-size: 14px; }
  .skip-button { min-height: 32px; padding: 5px 12px; font-size: 12px; }
  .number-key { min-height: 52px; border-radius: 15px; font-size: 25px; }
  .answer-button { min-height: 55px; margin-top: 7px; border-radius: 18px; font-size: 21px; }
}

/* ---------- Tablet landscape: problem and controls side-by-side ---------- */
@media (orientation: landscape) and (min-width: 700px) and (max-height: 900px) {
  .game-main {
    grid-template-columns: minmax(0, 1.06fr) minmax(390px, 0.94fr);
    grid-template-rows: 1fr;
    align-items: stretch;
    gap: 14px;
  }
  .controls {
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .number-key { min-height: clamp(56px, 10.5vh, 78px); }
  .answer-button { min-height: clamp(60px, 11vh, 78px); }
  .problem-card { min-height: 0; }
  .operand { font-size: clamp(68px, min(8.5vw, 13vh), 112px); }
  .celebration-burst { top: 64px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Compact phone landscape ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  .app-shell {
    padding: max(7px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .game-screen { gap: 7px; }
  .game-header { height: 42px; }
  .status-pill, .score-pill { border-radius: 14px; }
  .status-pill { min-width: 92px; padding: 4px 10px; }
  .status-pill .tiny-label { display: none; }
  .status-pill strong { width: 30px; height: 30px; font-size: 19px; }
  .score-pill { min-width: 112px; padding: 3px 10px; }
  .score-star { font-size: 20px; }
  .score-copy strong { margin-top: 2px; font-size: 19px; }
  .score-copy .tiny-label { font-size: 9px; }
  .score-unit { font-size: 10px; margin-bottom: 3px; }

  .game-main {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 0.92fr);
    grid-template-rows: 1fr;
    align-items: stretch;
    gap: 8px;
  }
  .problem-card {
    min-height: 0;
    padding: 6px 9px;
    gap: 4px;
    border-radius: 23px;
  }
  .problem-row { gap: clamp(6px, 1.8vw, 14px); }
  .operand { font-size: clamp(42px, min(7vw, 14vh), 64px); }
  .operator, .equals { font-size: clamp(31px, min(5vw, 10vh), 45px); }
  .answer-display {
    min-width: 104px;
    min-height: 48px;
    padding: 2px 14px;
    border-width: 3px;
    border-radius: 17px;
  }
  .answer-text { font-size: clamp(32px, min(5vw, 9vh), 42px); }
  .feedback-slot { min-height: 26px; }
  .feedback { font-size: 12px; }
  .skip-button { min-height: 28px; padding: 4px 10px; font-size: 11px; }

  .controls {
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .keypad { gap: 6px; }
  .number-key {
    min-height: 50px;
    border-radius: 14px;
    font-size: 24px;
  }
  .answer-button {
    min-height: 52px;
    margin-top: 7px;
    border-radius: 17px;
    font-size: 20px;
  }
}
