:root {
  --ink: #5b3a8c;
  --ink-soft: #8a6bb8;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-strong: rgba(255, 255, 255, 0.92);
  --shadow: 0 6px 0 rgba(120, 80, 170, 0.25), 0 12px 24px rgba(80, 40, 140, 0.18);
  --font: Fredoka, "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fdcff;
  font-family: var(--font);
  color: var(--ink);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; z-index: 20; }

#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#ui button, .pill { pointer-events: auto; }

.hidden { display: none !important; }

button {
  font-family: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(0.92); }

/* ---------- top bar ---------- */
.topbar {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  z-index: 2; /* stay above full-screen modals so 🏠 always works */
}
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.round {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--glass);
  box-shadow: var(--shadow);
  font-size: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  flex: none;
}
.round.off { opacity: 0.45; filter: grayscale(1); }

.pill {
  height: 44px;
  padding: 0 14px;
  border-radius: 22px;
  background: var(--glass);
  box-shadow: var(--shadow);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pill.bump { animation: bump 0.45s ease; }
.player-tag { height: 38px; font-size: 18px; margin-bottom: -14px; }

/* ---------- goal bar ---------- */
.goal {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 66px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  background: var(--glass);
  border-radius: 34px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 20px);
}
@media (min-width: 720px) { .goal { top: 0; } }

.dots {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), 26px);
  gap: 6px;
}
.dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px dashed rgba(138, 107, 184, 0.45);
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}
.dot.filled {
  border: 3px solid #fff;
  background: radial-gradient(circle at 35% 35%, #fff 0 15%, var(--c, #ffd84d) 60%);
  animation: bump 0.4s ease;
}
.dot.friend { background: #fff8d6; }

.bubble-icon {
  --c: 255, 120, 180;
  width: 50px;
  height: 50px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 28px;
  background: radial-gradient(circle at 32% 30%, rgba(255,255,255,0.95) 0 12%, rgba(var(--c), 0.35) 45%, rgba(var(--c), 0.95) 100%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.8);
  animation: float 2.4s ease-in-out infinite;
}
.bubble-icon.rainbow {
  background:
    radial-gradient(circle at 32% 30%, rgba(255,255,255,0.95) 0 12%, transparent 30%),
    conic-gradient(#ff8fb8, #ffd36e, #9ff0a7, #8fd0ff, #c9a3ff, #ff8fb8);
}
.bubble-icon.big { width: 130px; height: 130px; font-size: 70px; }

/* ---------- title ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: calc(80px + var(--safe-top)) 16px 24px;
}
.modal { pointer-events: auto; background: rgba(90, 50, 150, 0.28); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.logo {
  margin: 0;
  text-align: center;
  font-size: clamp(56px, 14vw, 120px);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: 2px;
}
.logo span {
  display: inline-block;
  color: #fff;
  text-shadow: 0 5px 0 var(--c), 0 10px 18px rgba(80, 40, 140, 0.35);
  -webkit-text-stroke: 3px var(--c);
  paint-order: stroke fill;
  animation: float 3s ease-in-out infinite;
}
.logo span:nth-child(6n+1) { --c: #ff7fb3; animation-delay: 0s; }
.logo span:nth-child(6n+2) { --c: #ffae4f; animation-delay: -0.4s; }
.logo span:nth-child(6n+3) { --c: #f5c400; animation-delay: -0.8s; }
.logo span:nth-child(6n+4) { --c: #4fcf86; animation-delay: -1.2s; }
.logo span:nth-child(6n+5) { --c: #4fa8ff; animation-delay: -1.6s; }
.logo span:nth-child(6n)   { --c: #a77bff; animation-delay: -2.0s; }

.play-btn {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  font-size: 64px;
  padding-left: 12px;
  color: #fff;
  background: radial-gradient(circle at 32% 28%, #fff 0 10%, #8fe39c 35%, #3fbf6e 100%);
  box-shadow: 0 8px 0 #2e9a57, 0 16px 30px rgba(40, 120, 70, 0.35), inset 0 0 0 5px rgba(255,255,255,0.6);
  animation: pulse 1.8s ease-in-out infinite;
  text-shadow: 0 3px 0 rgba(30, 110, 60, 0.4);
}
.play-btn.small { width: 110px; height: 110px; font-size: 48px; }

.row { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.mid-btn {
  min-width: 120px;
  padding: 12px 18px;
  border-radius: 28px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  font-size: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.mid-btn span { font-size: 17px; font-weight: 700; }

/* ---------- map ---------- */
.world-head { display: flex; align-items: center; gap: 14px; }
.world-head h2 {
  margin: 0;
  font-size: clamp(26px, 6vw, 44px);
  color: #fff;
  text-shadow: 0 3px 0 rgba(91, 58, 140, 0.55), 0 6px 14px rgba(60, 30, 110, 0.3);
  text-align: center;
  min-width: 8ch;
}
.arrow.invisible { visibility: hidden; }

.levels {
  position: relative;
  width: min(92vw, 560px);
  height: min(58vh, 520px);
}
.level {
  --c: 255, 180, 220;
  --s: clamp(96px, 22vw, 130px);
  position: absolute;
  width: var(--s);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  border-radius: 50%;
  font-size: clamp(40px, 10vw, 58px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 3px 0 rgba(91, 58, 140, 0.45);
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,0.95) 0 10%, rgba(var(--c), 0.45) 45%, rgba(var(--c), 1) 100%);
  box-shadow: 0 8px 18px rgba(80, 40, 140, 0.25), inset 0 0 0 5px rgba(255, 255, 255, 0.75);
  display: grid;
  place-items: center;
}
.level .lvl-stars {
  position: absolute;
  bottom: -16px;
  font-size: 20px;
  letter-spacing: -2px;
  text-shadow: none;
}
.level.locked { filter: grayscale(0.9); opacity: 0.65; font-size: 36px; }
.level.current { animation: pulse 1.6s ease-in-out infinite; }
.level.current::after {
  content: "👆";
  position: absolute;
  bottom: -46px;
  right: -14px;
  font-size: 44px;
  animation: float 1s ease-in-out infinite;
  text-shadow: none;
}
.path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }

/* ---------- cards ---------- */
.card {
  background: var(--glass-strong);
  border-radius: 36px;
  box-shadow: var(--shadow);
  padding: 22px 22px 26px;
  text-align: center;
  width: min(94vw, 560px);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  touch-action: pan-y;
  animation: popin 0.5s cubic-bezier(.2, 1.6, .4, 1);
}
.card h2 { margin: 0 0 8px; font-size: clamp(30px, 7vw, 48px); }
.card h3 { margin: 18px 0 8px; font-size: 26px; }

.book-card { position: relative; }
.book-card h2 { padding: 0 56px; text-wrap: balance; }
.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #fff4fb;
  font-weight: 700;
  color: var(--ink);
}

.win-card { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.win-stars { font-size: 64px; display: flex; gap: 6px; }
.win-stars span { opacity: 0; transform: scale(0); }
.win-stars.show span { animation: starin 0.55s cubic-bezier(.2, 1.8, .4, 1) forwards; }
.win-stars.show span:nth-child(2) { animation-delay: 0.35s; }
.win-stars.show span:nth-child(3) { animation-delay: 0.7s; }

.gift {
  font-size: 110px;
  background: none;
  line-height: 1;
  padding: 0;
  animation: wiggle 1s ease-in-out infinite;
  filter: drop-shadow(0 8px 12px rgba(80, 40, 140, 0.3));
}
.gift.opening { animation: shake 0.5s linear; }

.prize { display: flex; flex-direction: column; align-items: center; animation: popin 0.6s cubic-bezier(.2, 1.8, .4, 1); }
.prize-emoji { font-size: 120px; line-height: 1.1; animation: float 2s ease-in-out infinite; }
.prize-name { font-size: 30px; font-weight: 700; }
.actions { display: flex; gap: 22px; align-items: center; margin-top: 6px; }

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.sticker {
  aspect-ratio: 1;
  border-radius: 24px;
  background: #fff4fb;
  border: 3px dashed rgba(138, 107, 184, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(36px, 10vw, 56px);
  line-height: 1;
  padding: 4px;
}
.sticker small { font-size: 14px; margin-top: 4px; font-weight: 700; }
.sticker.got { border: 3px solid #ffd2ec; background: #fff; box-shadow: 0 4px 0 rgba(120, 80, 170, 0.15); }
.sticker.empty { color: rgba(138, 107, 184, 0.4); font-size: 34px; }
.sticker.wiggle { animation: wiggle 0.6s ease; }

.wand-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.wand {
  width: 86px;
  padding: 8px 4px;
  border-radius: 22px;
  background: #fff4fb;
  font-size: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 4px solid transparent;
}
.wand small { font-size: 14px; font-weight: 700; }
.wand.locked { filter: grayscale(1); opacity: 0.5; }
.wand.on { border-color: #ff8fc8; background: #fff; box-shadow: 0 0 0 4px rgba(255, 143, 200, 0.25); }

.reset-btn {
  margin-top: 22px;
  background: rgba(138, 107, 184, 0.12);
  border-radius: 16px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ink-soft);
  background-image: linear-gradient(90deg, rgba(255, 120, 160, 0.4) var(--p, 0%), transparent var(--p, 0%));
}

/* ---------- level intro ---------- */
.intro {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 26px 34px;
  border-radius: 40px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  font-size: clamp(26px, 6vw, 40px);
  font-weight: 700;
  text-align: center;
  animation: introfade 2.4s ease forwards;
  pointer-events: none;
}

/* ---------- animations ---------- */
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes popin { 0% { transform: scale(0.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes starin { 0% { opacity: 0; transform: scale(0) rotate(-90deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg) scale(1.05); } 75% { transform: rotate(9deg) scale(1.05); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-10px) rotate(-6deg); } 40%, 80% { transform: translateX(10px) rotate(6deg); } }
@keyframes introfade {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  25%, 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
}

@media (prefers-reduced-motion: reduce) {
  .logo span, .bubble-icon, .prize-emoji, .gift, .play-btn, .level.current { animation: none; }
}
