:root {
  --chalk: #1f3d2b;
  --chalk-2: #284d37;
  --paper: #fffaf0;
  --ink: #241a12;
  --orange: #ff7a2f;
  --yellow: #ffd23f;
  --green: #2fbf71;
  --red: #e5484d;
  --muted: #8a7a66;
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #f9d9a8;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .12);
}
[hidden] { display: none !important; }

/* ---------- danger glow when Mama is close ---------- */
#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 140px 30px rgba(229, 72, 77, .85);
  transition: opacity .2s;
}

/* ---------- top bar: start.ng profile card + buttons ---------- */
.topbar {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}
.topbar > * { pointer-events: auto; }
.card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: rgba(36, 26, 18, .88);
  color: var(--paper);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  max-width: min(360px, 70vw);
}
.card img, .face-fallback {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--yellow);
  flex: 0 0 40px;
  object-fit: cover;
}
.face-fallback { display: grid; place-items: center; font-weight: 900; color: var(--ink); }
.who { min-width: 0; }
.who b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { display: block; font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(36, 26, 18, .88);
  color: #fff;
  font-size: 18px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

/* ---------- in-game HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(70px + var(--safe-top)) 12px calc(14px + var(--safe-bottom));
  z-index: 4;
}
#hud > * { pointer-events: auto; }

.gap {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, 100%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(36, 26, 18, .85);
  color: #fff;
}
.gap-end { font-size: 20px; }
.gap-track {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
}
.gap-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  border-radius: inherit;
  background: var(--green);
  transition: background .3s;
}
.gap-runner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%) scaleX(-1);
  font-size: 22px;
}
.gap-m { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }

.board {
  margin-top: 10px;
  width: min(560px, 100%);
  padding: 12px 18px 14px;
  border-radius: 18px;
  background: var(--chalk);
  border: 6px solid #8b5e34;
  color: #f6f3e8;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.meta { display: flex; justify-content: space-between; font-size: 13px; font-weight: 800; opacity: .9; }
.streak.hot { color: var(--yellow); }
.question {
  font-size: clamp(40px, 9vw, 64px);
  font-weight: 900;
  letter-spacing: .02em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .25);
}
.question.pop { animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.85); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.timer { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: var(--yellow); border-radius: inherit; }
.timer i.slow { background: rgba(255, 255, 255, .35); }

.answers {
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: min(720px, 100%);
}
.answer {
  position: relative;
  min-height: 84px;
  border: 0;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 6px 0 #d6c4a5, 0 12px 24px rgba(0, 0, 0, .18);
  font-size: clamp(30px, 6vw, 40px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  transition: transform .06s;
  touch-action: manipulation;
}
.answer kbd { position: absolute; top: 8px; left: 10px; }
.answer:active, .answer.pressed { transform: translateY(4px); box-shadow: 0 2px 0 #d6c4a5, 0 6px 14px rgba(0, 0, 0, .18); }
.answer.right { background: #c9f5dc; }
.answer.wrong { background: #ffd4d4; }

/* ---------- feedback, banner, speech bubble ---------- */
.feedback {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  font-size: clamp(26px, 6vw, 38px);
  font-weight: 900;
  pointer-events: none;
  opacity: 0;
  z-index: 6;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .25);
  white-space: nowrap;
}
.feedback.show { animation: float 0.9s ease-out forwards; }
.feedback.good { color: #fff; -webkit-text-stroke: 1.5px #138a4b; }
.feedback.bad { color: #fff; -webkit-text-stroke: 1.5px #b0242a; }
@keyframes float {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.8); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(1); }
}
.banner {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  padding: 12px 22px;
  border-radius: 16px;
  background: var(--yellow);
  font-weight: 900;
  font-size: 22px;
  pointer-events: none;
  opacity: 0;
  z-index: 6;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
  white-space: nowrap;
}
.banner.show { animation: banner 1.8s ease-out forwards; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}
.bubble {
  position: fixed;
  z-index: 3;
  transform: translate(-50%, -100%);
  padding: 8px 12px;
  border-radius: 14px;
  background: #fff;
  font-weight: 900;
  font-size: 15px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .2);
  white-space: nowrap;
  pointer-events: none;
}
.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  border: 8px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
  transform: translateX(-50%);
}

/* ---------- overlays: menu, countdown, game over, pause ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: calc(76px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  overflow-y: auto;
}
.panel {
  width: min(440px, 100%);
  padding: 22px 24px;
  border-radius: 24px;
  background: rgba(255, 250, 240, .95);
  box-shadow: 0 20px 60px rgba(36, 26, 18, .25);
  backdrop-filter: blur(6px);
}
.small-panel { margin: auto; text-align: center; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; color: var(--orange); }
.panel h1 { margin: 4px 0 6px; font-size: clamp(34px, 7vw, 46px); line-height: 1; letter-spacing: -.01em; }
.panel h1 span { color: var(--orange); }
.tagline { margin: 0 0 12px; font-size: 16px; color: #5a4a38; }
.how { margin: 0 0 16px; padding-left: 18px; font-size: 14px; line-height: 1.55; }
.how em { color: var(--muted); font-style: normal; }
.big-btn {
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 16px;
  background: var(--orange);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 6px 0 #c25412, 0 12px 26px rgba(255, 122, 47, .35);
}
.big-btn kbd { background: rgba(255, 255, 255, .25); vertical-align: middle; margin-left: 6px; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #c25412; }
.guest-note { margin: 12px 0 0; font-size: 13px; color: #5a4a38; text-align: center; }
.link { border: 0; background: none; padding: 0; color: var(--orange); font-weight: 800; text-decoration: underline; }
.lb { margin-top: 16px; }
.lb h2 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.lb ol { margin: 0; padding: 0; list-style: none; font-size: 14px; }
.lb li { display: grid; grid-template-columns: 30px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 10px; }
.lb li:nth-child(odd) { background: rgba(0, 0, 0, .04); }
.lb li.me { background: #ffe9a8; font-weight: 800; }
.lb .rank { font-weight: 900; color: var(--muted); }
.lb .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.lb .pts { font-weight: 900; font-variant-numeric: tabular-nums; }
.lb .sub { color: var(--muted); font-size: 12px; }
.lb .empty { color: var(--muted); }

.countdown { justify-content: center; pointer-events: none; }
.countdown b {
  font-size: 140px;
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 4px var(--ink);
  text-shadow: 0 8px 0 rgba(0, 0, 0, .2);
}
.countdown b.tick { animation: pop .35s ease-out; }

.over-panel { text-align: center; }
.caught-title { color: var(--red); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.stats div { padding: 10px 4px; border-radius: 14px; background: #f3e8d4; }
.stats b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.save { min-height: 22px; margin: 0 0 12px; font-weight: 800; }
.save.good { color: #138a4b; }
.over-panel .pill { margin-top: 10px; }
.over-panel .lb { text-align: left; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .answers { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .answer { min-height: 72px; }
  .overlay { align-items: flex-end; padding-left: 12px; padding-right: 12px; }
  .panel { padding: 18px; }
  .stats b { font-size: 20px; }
  .board { padding: 8px 14px 10px; }
  #hud { padding-top: calc(66px + var(--safe-top)); }
}
@media (max-height: 560px) {
  .answer { min-height: 58px; }
  .question { font-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .feedback.show, .banner.show, .question.pop { animation-duration: .01s; }
}
