:root {
  --sky1: #fff3bf;
  --sky2: #fffbeb;
  --ink: #23395b;
  --accent: #f03e3e;
  --accent-shadow: #c92a2a;
  --good: #2bb673;
  --card: rgba(255, 255, 255, 0.95);
  --cheese: #ffd166;
  --cheese-on: #ffb347;
  --crust: #d9822b;
  --pep: #d6336c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: 'Baloo 2', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(var(--sky1), var(--sky2));
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
button:disabled { cursor: default; }
.hidden { display: none !important; }

.panel {
  background: var(--card); border-radius: 28px; padding: 28px 24px; width: min(560px, 100%);
  text-align: center; box-shadow: 0 12px 0 rgba(35, 57, 91, .1), 0 20px 40px rgba(35, 57, 91, .12);
}
h1 { font-size: clamp(1.9rem, 6vw, 2.6rem); line-height: 1.15; }
h2 { font-size: 1.1rem; margin: 18px 0 8px; opacity: .8; }
.sub { opacity: .75; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.choices { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.choices button {
  background: #fff5f5; border-radius: 16px; padding: 10px 16px; font-size: 1.1rem; font-weight: 700;
  border: 3px solid transparent; display: flex; flex-direction: column; align-items: center; line-height: 1.2;
}
.choices button small { font-size: .75rem; font-weight: 500; opacity: .7; }
.choices button.active { border-color: var(--accent); background: #fff; }

.big {
  margin-top: 22px; background: var(--accent); color: #fff; font-size: 1.35rem; font-weight: 800;
  padding: 12px 32px; border-radius: 999px; box-shadow: 0 6px 0 var(--accent-shadow); transition: transform .1s, box-shadow .1s;
}
.big:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-shadow); }
.big.ghost { background: #fff5f5; color: var(--ink); box-shadow: 0 6px 0 #f5c6c6; }
.big.go { background: var(--good); box-shadow: 0 6px 0 #1e8c57; margin-top: 8px; }
.best { margin-top: 12px; font-weight: 700; color: #b07a00; min-height: 1.5em; }

#menu, #result { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

/* ---------- HUD ---------- */
#game { max-width: 820px; margin: 0 auto; padding: 10px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
.hud { display: flex; align-items: center; gap: 10px; }
.icon {
  background: var(--card); width: 44px; height: 44px; border-radius: 14px; font-size: 1.3rem;
  box-shadow: 0 3px 0 rgba(35, 57, 91, .15); flex-shrink: 0;
}
.icon.off { opacity: .4; }
.progress { flex: 1; min-width: 0; }
.bar { height: 14px; background: rgba(255, 255, 255, .8); border-radius: 99px; overflow: hidden; }
#progressFill { height: 100%; width: 0; background: linear-gradient(90deg, #ffd43b, var(--accent)); border-radius: 99px; transition: width .4s; }
#progressText { font-size: .85rem; font-weight: 700; }
.score { background: var(--card); padding: 6px 14px; border-radius: 14px; font-size: 1.2rem; font-weight: 800; white-space: nowrap; }

.guide { display: flex; align-items: center; gap: 4px; min-height: 70px; }
.guide .mascot { width: 70px; height: 70px; }
.guide .bubble { margin: 0; white-space: normal; font-size: 1.05rem; flex: 1; }

/* ---------- Sân khấu ---------- */
.stage { background: var(--card); border-radius: 24px; padding: 16px; text-align: center; }
.question {
  font-size: clamp(1.25rem, 4.4vw, 1.7rem); font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
}
.friends { font-size: 2.4rem; letter-spacing: 6px; min-height: 0; }
.friends:empty { display: none; }
.hint { color: #e8590c; font-weight: 700; min-height: 1.5em; }

/* Phân số viết dọc: tử số / mẫu số */
.frac { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; font-weight: 800; vertical-align: middle; }
.frac b { padding: 0 4px; }
.frac i { width: 100%; height: 3px; background: currentColor; border-radius: 2px; margin: 3px 0; }
.question .frac { font-size: 1.5em; color: var(--accent); }

.pizzas { display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; margin: 8px 0; }
.pizza-box { display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 24px; padding: 6px; background: none; }
button.pizza-box { border: 4px solid transparent; transition: transform .12s; }
button.pizza-box:hover:not(:disabled) { transform: translateY(-4px); border-color: #ffd8a8; }
button.pizza-box.wrong { opacity: .4; animation: shake .4s; }
button.pizza-box.right { border-color: var(--good); }
.pizza-box .frac { font-size: 1.5rem; }
.pizza { width: min(260px, 70vw); height: auto; display: block; }
.pizzas.two .pizza { width: min(200px, 40vw); }
.pizza.spin { animation: spinIn .6s ease-out; }
@keyframes spinIn { from { transform: rotate(-120deg) scale(.6); opacity: 0; } }
.pizza .plate { fill: #fff; stroke: #e9ecef; stroke-width: 3; }
.pizza .crust { fill: var(--crust); }
.pizza .slice { fill: var(--cheese); stroke: #fff8e1; stroke-width: 2.5; transition: fill .15s; }
.pizza .slice.on { fill: var(--cheese-on); }
.pizza.tappable .slice { cursor: pointer; }
.pizza.tappable .slice:hover { fill: #ffe08a; }
.pizza.tappable .slice.on:hover { fill: #ffa94d; }
.pizza .pep { fill: var(--pep); pointer-events: none; animation: pepIn .2s; transform-box: fill-box; transform-origin: center; }
.pizza .pep-dot { fill: #a61e4d; pointer-events: none; }
@keyframes pepIn { from { transform: scale(0); } }

.options { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 4px; }
.options .opt {
  background: #fff5f5; border-radius: 18px; padding: 8px 22px; font-size: 1.6rem; min-width: 84px;
  box-shadow: 0 5px 0 #f5c6c6; transition: transform .1s;
}
.options .opt:active:not(:disabled) { transform: translateY(3px); }
.options .opt.wrong { opacity: .35; animation: shake .4s; }
.options .opt.right { background: var(--good); color: #fff; box-shadow: 0 5px 0 #1e8c57; }
.options .opt.text { font-size: 1.2rem; font-weight: 800; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Kết quả ---------- */
.stars { font-size: 4rem; margin: 10px 0; letter-spacing: 6px; }
.stars span { display: inline-block; filter: grayscale(1); opacity: .3; }
.stars span.on { filter: none; opacity: 1; animation: starIn .5s backwards; }
.stars span:nth-child(2) { animation-delay: .25s; }
.stars span:nth-child(3) { animation-delay: .5s; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3); } }
.stat { font-size: 1.2rem; }
.confetti { position: fixed; top: -20px; width: 10px; height: 16px; z-index: 10; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 520px) {
  .icon { width: 38px; height: 38px; font-size: 1.1rem; }
  .hud { gap: 6px; }
  .pizzas { gap: 8px; }
  .options .opt { font-size: 1.35rem; padding: 6px 16px; min-width: 70px; }
}
