:root {
  --panel: rgba(16, 10, 38, 0.82);
  --gold: #ffd23f;
  --accent: #3ccf6e;
  --font: 'Fredoka', 'Chalkboard SE', 'Comic Sans MS', 'Trebuchet MS', sans-serif;
  --spooky: 'Creepster', 'Chalkduster', 'Fredoka', fantasy;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05030d;
  color: #fff;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
  z-index: 5;
}

.hud-left { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hud-right { justify-self: end; padding-right: 4px; }

.pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  font-size: clamp(14px, 2.2vh, 18px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.world-name { color: var(--accent); transition: color 0.6s; }

.dots, .track { display: flex; gap: 5px; }

.dots i {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.3s, box-shadow 0.3s;
}
.dots i.on { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.steps .mini-ghost { width: 24px; height: 26px; filter: drop-shadow(0 0 6px rgba(170, 215, 255, 0.9)); }
.track i {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  transition: background 0.3s;
}
.steps.safe .track i.on { background: #4ade80; }
.steps.warn .track i.on { background: #facc15; }
.steps.danger .track i.on { background: #f87171; }
.steps.danger { border-color: #f87171; animation: dangerPulse 0.8s ease-in-out infinite; }
.steps-label { min-width: 7.5em; }

@keyframes dangerPulse {
  50% { box-shadow: 0 0 22px rgba(248, 113, 113, 0.85); }
}

/* Treasure chest */

.chest {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 2px solid rgba(255, 210, 63, 0.5);
  border-radius: 22px;
  padding: 6px 18px 6px 10px;
  box-shadow: 0 0 22px rgba(255, 200, 60, 0.25), 0 4px 14px rgba(0, 0, 0, 0.4);
}
.chest svg { width: clamp(46px, 7vh, 64px); height: auto; overflow: visible; }
.coin-count {
  font-size: clamp(26px, 4.5vh, 40px);
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 2px 0 #9a5b00, 0 0 12px rgba(255, 210, 63, 0.6);
  min-width: 1.4ch;
  text-align: center;
}
.chest .lid { transform-box: fill-box; transform-origin: 0% 100%; }
.chest.bump svg { animation: chestBump 0.45s ease; }
.chest.bump .lid { animation: lidPop 0.45s ease; }
.chest.bump .coin-count { animation: countPop 0.45s ease; }

@keyframes chestBump {
  40% { transform: scale(1.25) rotate(-6deg); }
}
@keyframes lidPop {
  40% { transform: translateY(-6px) rotate(-22deg); }
}
@keyframes countPop {
  40% { transform: scale(1.4); }
}

/* Level badge */

.badge {
  position: relative;
  width: clamp(84px, 13vh, 116px);
  aspect-ratio: 1;
  filter: drop-shadow(0 0 14px rgba(255, 200, 60, 0.6));
  animation: badgeIn 0.9s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.badge svg { width: 100%; height: 100%; animation: badgeWiggle 3s ease-in-out infinite; }
.badge-num {
  position: absolute;
  inset: 0 0 8% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #7a3f00;
  font-weight: 700;
  font-size: clamp(22px, 3.6vh, 32px);
  line-height: 0.9;
}
.badge-num small { font-size: 0.45em; letter-spacing: 0.08em; }
.badge-ribbon {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  background: #e2395b;
  color: #fff;
  font-weight: 700;
  font-size: clamp(11px, 1.7vh, 14px);
  padding: 3px 10px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 3px 0 #8f1d36;
}

@keyframes badgeIn {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes badgeWiggle {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

/* ---------- Question panel ---------- */

.question {
  position: fixed;
  left: 50%;
  top: max(118px, 17vh);
  width: min(680px, 94vw);
  transform: translateX(-50%);
  background: var(--panel);
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-radius: 30px;
  padding: clamp(10px, 2vh, 20px) clamp(14px, 2.5vw, 26px);
  text-align: center;
  z-index: 6;
  box-shadow: 0 0 40px rgba(120, 90, 255, 0.35), 0 12px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: panelIn 0.45s cubic-bezier(0.2, 1.5, 0.4, 1);
}

@keyframes panelIn {
  from { transform: translateX(-50%) scale(0.6); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

.q-label {
  font-size: clamp(12px, 1.9vh, 16px);
  color: #c9b8ff;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}

.q-text {
  font-size: clamp(38px, 8.5vh, 76px);
  font-weight: 700;
  line-height: 1.15;
  margin: 2px 0 clamp(8px, 1.8vh, 16px);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(8px, 1.5vw, 14px); }

.choice {
  height: clamp(60px, 11vh, 96px);
  border: none;
  border-radius: 20px;
  font-size: clamp(28px, 5.5vh, 46px);
  font-weight: 700;
  color: #fff;
  background: var(--c);
  box-shadow: 0 6px 0 var(--d), 0 10px 18px rgba(0, 0, 0, 0.35);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.1s, filter 0.2s, opacity 0.2s, background 0.2s;
}
.choice:nth-child(1) { --c: #8b5cf6; --d: #5b30c0; }
.choice:nth-child(2) { --c: #06b6d4; --d: #0b7d93; }
.choice:nth-child(3) { --c: #f97316; --d: #b4500c; }
.choice:nth-child(4) { --c: #ec4899; --d: #a52466; }
.choice:hover:not(:disabled) { transform: translateY(-3px); filter: brightness(1.12); }
.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--d); }
.choice:disabled { cursor: default; }
.choice.right { --c: #22c55e; --d: #15803d; animation: pop 0.5s; }
.choice.wrong { --c: #ef4444; --d: #991b1b; animation: shake 0.45s; }
.choice.dim { opacity: 0.3; }

.q-feedback {
  min-height: 1.4em;
  margin-top: clamp(6px, 1.4vh, 12px);
  font-size: clamp(18px, 3vh, 26px);
  font-weight: 700;
}
.q-feedback.good { color: #86efac; }
.q-feedback.bad { color: #fca5a5; }

@keyframes pop {
  40% { transform: scale(1.15); }
}
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@media (max-width: 560px) {
  .choices { grid-template-columns: repeat(2, 1fr); }
  .hud { grid-template-columns: 1fr auto; padding-left: 10px; padding-right: 10px; }
  .hud-right { position: fixed; right: 12px; top: 96px; }
  .pill { padding: 5px 10px; gap: 7px; }
  .steps-label { display: none; }
  .chest { padding-right: 12px; }
}

/* ---------- World / level banner ---------- */

.banner {
  position: fixed;
  left: 0; right: 0;
  top: 30%;
  text-align: center;
  pointer-events: none;
  z-index: 7;
  opacity: 0;
}
.banner.show { animation: bannerIn 2.6s ease forwards; }
.banner-title {
  font-size: clamp(38px, 7.5vw, 92px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 24px var(--accent), 0 5px 0 rgba(0, 0, 0, 0.45);
}
.banner-sub {
  font-size: clamp(18px, 3vh, 28px);
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}
.banner.levelup .banner-title {
  color: var(--gold);
  font-size: clamp(54px, 11vw, 130px);
  text-shadow: 0 0 30px rgba(255, 200, 60, 0.9), 0 6px 0 #9a5b00;
}
.banner.levelup .banner-sub { color: #fff3a0; }

@keyframes bannerIn {
  0% { opacity: 0; transform: scale(0.4); }
  15% { opacity: 1; transform: scale(1.08); }
  22% { transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-20px) scale(1.1); }
}

/* ---------- Intro + game over screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 20px 22vh;
  z-index: 10;
}

.intro {
  background: radial-gradient(ellipse at 50% 35%, rgba(20, 10, 50, 0.3), rgba(3, 2, 12, 0.72) 75%);
}

.intro-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 18px);
  text-align: center;
}

.title { line-height: 0.9; font-weight: 400; }
.title .t1 {
  display: block;
  font-family: var(--spooky);
  font-size: clamp(56px, min(16vh, 22vw), 150px);
  letter-spacing: 0.04em;
  color: #d8ffe4;
  text-shadow: 0 0 18px #6dffb0, 0 0 50px rgba(80, 255, 170, 0.6), 0 6px 0 #1f5e3d;
  animation: floaty 3s ease-in-out infinite;
}
.title .t2 {
  display: block;
  font-family: var(--spooky);
  font-size: clamp(30px, min(8.5vh, 11vw), 80px);
  letter-spacing: 0.06em;
  color: #c9a8ff;
  text-shadow: 0 0 16px #9b6bff, 0 4px 0 #3b1f78;
}

@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}

.tagline {
  font-size: clamp(16px, 2.6vh, 24px);
  color: #e9e3ff;
  max-width: 32ch;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}

.big-btn {
  font-size: clamp(30px, 6vh, 52px);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #2a1440;
  background: linear-gradient(#fff07a, #ffc21a);
  border: none;
  border-radius: 999px;
  padding: 0.3em 1.6em;
  box-shadow: 0 8px 0 #b77a00, 0 0 40px rgba(255, 210, 63, 0.6);
  animation: pulse 1.4s ease-in-out infinite;
  transition: transform 0.1s;
}
.big-btn:hover { filter: brightness(1.08); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 3px 0 #b77a00, 0 0 40px rgba(255, 210, 63, 0.6); }

@keyframes pulse {
  50% { scale: 1.07; box-shadow: 0 8px 0 #b77a00, 0 0 70px rgba(255, 210, 63, 0.95); }
}

.howto { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 840px; }
.how {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 260px;
  padding: 8px 12px;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  font-size: clamp(13px, 1.9vh, 16px);
  text-align: left;
}
.how-icon {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.how-icon.good { background: #22c55e; }
.how-icon.bad { background: #ef4444; }
.how-icon.world { background: #8b5cf6; }

.best { color: var(--gold); font-weight: 600; font-size: clamp(15px, 2.2vh, 20px); min-height: 1.2em; }

.over {
  padding-bottom: 20px;
  background: radial-gradient(ellipse at center, rgba(40, 10, 60, 0.55), rgba(3, 2, 12, 0.85));
  animation: fadeIn 0.6s ease;
}
.over-card {
  width: min(560px, 94vw);
  padding: clamp(16px, 3vh, 30px) clamp(18px, 4vw, 40px);
  text-align: center;
  background: var(--panel);
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-radius: 32px;
  box-shadow: 0 0 60px rgba(150, 100, 255, 0.35);
  animation: cardIn 0.6s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.over-title {
  font-family: var(--spooky);
  font-size: clamp(56px, 12vh, 110px);
  line-height: 1;
  color: #d8ffe4;
  text-shadow: 0 0 20px #6dffb0, 0 5px 0 #1f5e3d;
}
.over-sub { font-size: clamp(16px, 2.6vh, 22px); color: #e9e3ff; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: clamp(10px, 2vh, 18px) 0; }
.stat { background: rgba(255, 255, 255, 0.07); border-radius: 18px; padding: 8px; }
.stat-num { font-size: clamp(24px, 4.6vh, 38px); font-weight: 700; color: var(--gold); }
.stat-label { font-size: 13px; color: #c9b8ff; text-transform: uppercase; letter-spacing: 0.1em; }

.new-best {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 16px;
  background: #e2395b;
  border-radius: 10px;
  font-weight: 700;
  font-size: clamp(16px, 2.6vh, 22px);
  box-shadow: 0 3px 0 #8f1d36;
  animation: pop 0.8s ease infinite;
}

.over-buttons { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 12px; }
.small-btn {
  padding: 8px 28px;
  font-size: 18px;
  font-weight: 600;
  color: #c9b8ff;
  background: transparent;
  border: 2px solid rgba(201, 184, 255, 0.4);
  border-radius: 999px;
}
.small-btn:hover { background: rgba(201, 184, 255, 0.12); }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes cardIn { from { transform: scale(0.6); opacity: 0; } }

/* ---------- Sound toggle ---------- */

.mute {
  position: fixed;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 48px; height: 48px;
  display: grid;
  place-items: center;
  color: #e9e3ff;
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  z-index: 20;
}
.mute svg { width: 26px; height: 26px; }
.mute .slash { display: none; }
.mute.muted .waves { display: none; }
.mute.muted .slash { display: inline; }
