:root {
  color-scheme: dark;
  --ink: #221942;
  --ink-2: #33215b;
  --cream: #fff7d6;
  --yellow: #ffd84d;
  --orange: #ff9d3b;
  --tomato: #f24f52;
  --mint: #72e6b1;
  --sky: #78d9ff;
  --white: #fffdf3;
  font-family: "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--ink);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--white);
  background:
    radial-gradient(circle at 13% 18%, #54377c 0 1px, transparent 2px) 0 0 / 44px 44px,
    radial-gradient(circle at 87% 72%, #6f4786 0 2px, transparent 3px) 0 0 / 71px 71px,
    linear-gradient(135deg, #241943 0%, #392052 53%, #20183c 100%);
  overscroll-behavior: none;
}

button, a { -webkit-tap-highlight-color: transparent; }

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

button:focus-visible, a:focus-visible {
  outline: 4px solid var(--sky);
  outline-offset: 3px;
}

.topbar {
  min-height: 60px;
  padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #ffffff1c;
  background: #1a1234c9;
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--cream);
  text-decoration: none;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .12em;
}

.brand-pizza {
  position: relative;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--yellow);
  border: 3px solid #f2a235;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: inset 6px 0 var(--tomato);
  font-size: 0;
}

.brand-pizza::after {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #d94145;
  box-shadow: 8px 3px #d94145, 3px 9px #d94145;
}

.brand-small { display: none; }

.sound-button {
  min-height: 38px;
  padding: 0 14px;
  flex: 0 0 auto;
  border: 1px solid #ffffff2b;
  border-radius: 999px;
  color: var(--cream);
  background: #ffffff10;
  font-size: 12px;
  font-weight: 900;
}

.page-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 56px) clamp(14px, 3.4vw, 42px) 34px;
  display: grid;
  grid-template-columns: minmax(330px, .82fr) minmax(460px, 620px);
  align-items: center;
  justify-content: center;
  gap: clamp(30px, 5vw, 76px);
}

.story { max-width: 480px; }

.eyebrow {
  margin: 0 0 14px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .19em;
}

h1 {
  margin: 0;
  color: var(--yellow);
  font-size: clamp(54px, 6vw, 86px);
  line-height: .93;
  letter-spacing: -.07em;
  text-shadow: 0 7px 0 #b94349, 0 13px 30px #100b25b8;
}

h1 span {
  color: var(--white);
  font-size: .55em;
  letter-spacing: -.03em;
  text-shadow: none;
}

.lead {
  margin: 27px 0 21px;
  color: #f8eaff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.8;
}

.mini-lesson {
  width: max-content;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 13px;
  border: 1px solid #ffffff24;
  border-radius: 18px;
  background: #ffffff0d;
}

.mini-pizza {
  width: 47px;
  aspect-ratio: 1;
  border: 4px solid #e79930;
  border-radius: 50%;
  background: conic-gradient(var(--tomato) 0 50%, var(--yellow) 50%);
  box-shadow: inset 0 0 0 2px #ffe893;
}

.mini-pizza.quarters {
  background: conic-gradient(var(--tomato) 0 25%, var(--yellow) 25% 50%, var(--tomato) 50% 75%, var(--yellow) 75%);
}

.mini-lesson strong {
  width: 24px;
  display: grid;
  text-align: center;
  color: var(--white);
  font-size: 17px;
  line-height: 1;
}

.mini-lesson strong i { margin: 3px 0; border-top: 2px solid; }
.mini-lesson b { color: var(--mint); font-size: 22px; }

.lesson-copy {
  margin: 8px 0 24px 3px;
  color: #d5c5e4;
  font-size: 12px;
  font-weight: 700;
}

.steps {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  list-style: none;
}

.steps li {
  padding: 13px 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid #ffffff22;
  color: #d9cce6;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.45;
}

.steps b {
  color: #8060a1;
  font-size: 23px;
  font-style: italic;
}

.steps em { color: var(--cream); font-size: 11px; font-style: normal; }

.save-copy {
  margin: 20px 0 0;
  color: #9885ad;
  font-size: 10px;
  line-height: 1.7;
}

.game-panel {
  width: 100%;
  max-width: 620px;
  padding: 13px;
  border: 1px solid #ffffff2c;
  border-radius: 28px;
  background: #140e2ad9;
  box-shadow: 0 28px 70px #0c081dbd, inset 0 1px #ffffff1c;
}

.scorebar {
  min-height: 54px;
  padding: 3px 12px 8px;
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr;
  align-items: center;
  text-align: center;
}

.scorebar div { display: grid; gap: 0; }
.scorebar small { color: #9f8eb1; font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.scorebar strong { color: var(--cream); font-size: 24px; line-height: 1; font-variant-numeric: tabular-nums; }
.scorebar .score-center strong { color: var(--yellow); font-size: 29px; }

.fever-meter {
  position: relative;
  height: 17px;
  margin: 0 7px 10px;
  overflow: hidden;
  border: 2px solid #412d62;
  border-radius: 999px;
  background: #0d0920;
}

.fever-meter span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff5b72, #ffd84d 52%, #72e6b1);
  transition: width .25s ease;
}

.fever-meter b {
  position: relative;
  z-index: 1;
  display: block;
  color: #fff;
  font-size: 8px;
  line-height: 13px;
  text-align: center;
  letter-spacing: .12em;
  text-shadow: 0 1px 2px #000;
}

.fever-meter.active { border-color: var(--yellow); box-shadow: 0 0 18px #ffd84d82; }
.fever-meter.active span { width: 100% !important; animation: fever-shine .7s linear infinite; }

.stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 2px solid #ffffff1a;
  border-radius: 19px;
  background: #302050;
  isolation: isolate;
  touch-action: none;
  user-select: none;
}

#game-canvas { width: 100%; height: auto; display: block; }

.overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  padding: 18px;
  display: grid;
  place-items: center;
  overflow-y: auto;
  background: #1b123ab8;
  backdrop-filter: blur(6px);
}

.overlay.empty { display: none; }

.card {
  width: min(470px, 100%);
  padding: clamp(18px, 4vw, 30px);
  border: 2px solid #ffffff24;
  border-radius: 26px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 18px 50px #100a29ad, inset 0 2px #fff;
  text-align: center;
}

.card .kicker {
  margin: 0 0 5px;
  color: #d3484e;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .18em;
}

.card h2 {
  margin: 0 0 7px;
  color: var(--ink);
  font-size: clamp(22px, 5vw, 32px);
  line-height: 1.15;
}

.card > p:not(.kicker):not(.best-line):not(.result-copy) {
  margin: 7px 0 17px;
  color: #695b78;
  font-size: 12px;
  line-height: 1.6;
}

.mascot-row {
  height: 62px;
  margin: -3px 0 4px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
}

.mascot-row span {
  display: grid;
  place-items: center;
  width: 53px;
  height: 53px;
  border-radius: 48% 52% 46% 54%;
  background: var(--monster, #79dcb4);
  box-shadow: inset 0 -7px #00000010;
  font-size: 28px;
  animation: monster-bob 1.5s ease-in-out infinite alternate;
}

.mascot-row span:nth-child(2) { width: 64px; height: 64px; animation-delay: -.7s; }
.mascot-row span:nth-child(3) { animation-delay: -1.1s; }

.mode-list { display: grid; gap: 9px; }

.mode-button {
  width: 100%;
  min-height: 67px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 45px 1fr auto;
  align-items: center;
  gap: 11px;
  border: 2px solid #e6dba9;
  border-radius: 17px;
  color: var(--ink);
  background: #fffdf1;
  text-align: left;
  box-shadow: 0 4px 0 #d7c884;
  transition: transform .13s ease, border-color .13s ease;
}

.mode-button:hover { transform: translateY(-2px); border-color: #f1a637; }
.mode-button:active { transform: translateY(2px); box-shadow: 0 1px 0 #d7c884; }
.mode-icon { font-size: 30px; text-align: center; }
.mode-button strong { display: block; font-size: 16px; }
.mode-button small { display: block; margin-top: 3px; color: #776780; font-size: 10px; font-weight: 700; line-height: 1.35; }
.mode-tag { padding: 4px 8px; border-radius: 999px; color: #733b00; background: #ffd976; font-size: 9px; font-weight: 900; }
.mode-button.challenge { border-color: #c8b6e5; background: #f6f0ff; box-shadow-color: #bba7dc; }
.mode-button.challenge .mode-tag { color: #fff; background: #7549a6; }

.sticker-line, .best-line {
  margin: 13px 0 0;
  color: #786985;
  font-size: 10px;
  font-weight: 800;
}

.sticker-strip { margin-top: 7px; display: flex; justify-content: center; gap: 5px; }
.sticker-strip span { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; background: #e6ddc5; filter: grayscale(1); opacity: .42; font-size: 17px; }
.sticker-strip span.got { background: #ffd86c; filter: none; opacity: 1; box-shadow: 0 3px 0 #e4b336; }

.primary, .secondary {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 900;
}

.primary { color: #fff; background: #ed4e53; box-shadow: 0 5px 0 #a8333e; }
.secondary { color: #4b3d59; background: #e9dfc8; box-shadow: 0 4px 0 #cfc19f; }
.primary:active, .secondary:active { transform: translateY(3px); box-shadow: none; }

.home-how { margin-top: 14px; min-height: 37px; padding: 0 14px; border-radius: 10px; color: #6c5d7b; background: transparent; font-size: 11px; font-weight: 900; text-decoration: underline; }

.how-grid { display: grid; gap: 9px; margin: 15px 0 18px; text-align: left; }
.how-item { display: grid; grid-template-columns: 39px 1fr; align-items: center; gap: 10px; }
.how-item b { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: #ec5257; font-size: 16px; }
.how-item span { color: #5d4e6a; font-size: 11px; font-weight: 700; line-height: 1.5; }
.fraction-demo { margin: 10px auto 6px; display: flex; align-items: center; justify-content: center; gap: 14px; }
.demo-pizza { width: 80px; height: 80px; border: 6px solid #e79c35; border-radius: 50%; background: conic-gradient(#ef5558 0 50%, #ffd84d 50%); box-shadow: inset 0 0 0 3px #fff1a6; }
.fraction-big { width: 40px; display: grid; color: #35254d; font-size: 27px; line-height: 1; }
.fraction-big i { margin: 4px 0; border-top: 4px solid; }

.result-medal { margin: 5px auto 7px; font-size: 62px; line-height: 1; filter: drop-shadow(0 6px 0 #c7a84d); }
.result-score { margin: 7px 0 0; color: #d3484e; font-size: clamp(36px, 9vw, 55px); line-height: 1; }
.result-score small { font-size: 13px; }
.result-copy { margin: 8px 0 12px; color: #655572; font-size: 11px; font-weight: 800; line-height: 1.5; }
.new-sticker { margin: 8px 0; padding: 8px; border-radius: 12px; color: #664805; background: #ffe68e; font-size: 11px; font-weight: 900; }
.action-row { display: grid; grid-template-columns: 1fr 1.35fr; gap: 9px; margin-top: 13px; }

.toast {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 44%;
  min-width: 170px;
  padding: 10px 17px;
  border: 2px solid #ffffffb3;
  border-radius: 999px;
  color: #fff;
  background: #21163edb;
  box-shadow: 0 7px 30px #130a2b99;
  font-size: 15px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px) scale(.85);
  transition: opacity .15s ease, transform .15s ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.good { color: #24173e; background: var(--yellow); border-color: #fff4b7; }
.toast.bad { background: #c83b51e8; }

.countdown {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--yellow);
  background: #21143ec7;
  font-size: clamp(80px, 20vw, 140px);
  font-weight: 900;
  text-shadow: 0 8px 0 #b33d4b;
}

.countdown.show { display: grid; }

.action-controls { display: grid; grid-template-columns: .8fr 1.4fr; gap: 9px; margin-top: 10px; }
.action-controls button { min-height: 51px; border-radius: 15px; font-size: 13px; font-weight: 900; }
.action-controls button:disabled { cursor: default; filter: grayscale(.3); opacity: .45; box-shadow: none; }
.clear-button { color: #d8cbe5; background: #2d2049; border: 1px solid #ffffff1e; }
.serve-button { color: #3b2100; background: var(--yellow); box-shadow: 0 5px 0 #c18b25; }
.serve-button span { margin-left: 7px; }
.serve-button:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 #c18b25; }

.menu-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 10px; }
.menu-controls button { min-height: 36px; border-radius: 10px; color: #aa98ba; background: #ffffff0b; font-size: 10px; font-weight: 800; }
.menu-controls button:hover { color: #fff; background: #ffffff13; }

footer {
  padding: 15px 20px max(21px, env(safe-area-inset-bottom));
  color: #79688e;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .28em;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes monster-bob { to { transform: translateY(-6px) rotate(2deg); } }
@keyframes fever-shine { to { filter: hue-rotate(80deg) brightness(1.25); } }

@media (max-width: 900px) {
  .page-shell { grid-template-columns: minmax(0, 620px); padding-top: 22px; }
  .story { max-width: 620px; text-align: center; }
  .eyebrow { margin-bottom: 8px; }
  h1 { font-size: clamp(48px, 12vw, 74px); }
  .lead { margin: 18px 0 14px; font-size: 14px; }
  .mini-lesson { margin: 0 auto; }
  .lesson-copy { margin-bottom: 10px; }
  .steps, .save-copy { display: none; }
}

@media (max-width: 520px) {
  .topbar { min-height: 52px; padding-left: 12px; padding-right: 12px; }
  .brand-wide { display: none; }
  .brand-small { display: inline; font-size: 11px; letter-spacing: .04em; }
  .sound-button { min-height: 34px; padding: 0 11px; font-size: 10px; }
  .page-shell { padding: 13px 7px 19px; gap: 17px; }
  .story { padding: 0 8px; }
  .eyebrow { font-size: 8px; }
  h1 { font-size: 46px; text-shadow: 0 5px 0 #b94349; }
  .lead { margin: 12px 0 0; font-size: 11px; line-height: 1.6; }
  .mini-lesson, .lesson-copy { display: none; }
  .game-panel { padding: 7px; border-radius: 19px; }
  .scorebar { min-height: 47px; padding-bottom: 5px; }
  .scorebar strong { font-size: 20px; }
  .scorebar .score-center strong { font-size: 24px; }
  .fever-meter { margin: 0 5px 7px; }
  .stage { border-radius: 14px; }
  .overlay { padding: 9px; align-items: center; }
  .card { padding: 15px 14px; border-radius: 20px; }
  .card h2 { font-size: 23px; }
  .card > p:not(.kicker):not(.best-line):not(.result-copy) { margin: 5px 0 11px; font-size: 10px; }
  .mascot-row { height: 45px; }
  .mascot-row span { width: 38px; height: 38px; font-size: 20px; }
  .mascot-row span:nth-child(2) { width: 46px; height: 46px; }
  .mode-list { gap: 6px; }
  .mode-button { min-height: 57px; padding: 7px 10px; grid-template-columns: 36px 1fr auto; gap: 7px; }
  .mode-icon { font-size: 25px; }
  .mode-button strong { font-size: 14px; }
  .mode-button small { font-size: 8px; }
  .mode-tag { padding: 3px 6px; font-size: 7px; }
  .sticker-line { margin-top: 8px; }
  .sticker-strip { margin-top: 4px; }
  .sticker-strip span { width: 25px; height: 25px; font-size: 14px; }
  .home-how { margin-top: 7px; min-height: 29px; }
  .action-controls { margin-top: 7px; gap: 6px; }
  .action-controls button { min-height: 45px; font-size: 11px; }
  .menu-controls { margin-top: 7px; gap: 5px; }
  .menu-controls button { min-height: 32px; font-size: 8px; }
  .how-grid { gap: 6px; margin: 9px 0 12px; }
  .how-item { grid-template-columns: 31px 1fr; gap: 7px; }
  .how-item b { width: 30px; height: 30px; font-size: 12px; }
  .how-item span { font-size: 9px; }
  .fraction-demo { margin: 4px auto; }
  .demo-pizza { width: 55px; height: 55px; border-width: 4px; }
  .fraction-big { font-size: 20px; }
  .primary, .secondary { min-height: 41px; font-size: 11px; }
  .result-medal { font-size: 47px; }
  .result-score { font-size: 37px; }
  footer { padding-top: 7px; }
}

@media (max-height: 760px) and (max-width: 520px) {
  .story { display: none; }
  .page-shell { padding-top: 8px; }
  .game-panel { max-width: 470px; margin: 0 auto; }
}

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