:root {
  --pink: #ff5fa2;
  --pink-dark: #e23e85;
  --bg1: #2a1a40;
  --bg2: #46225f;
  --panel: rgba(255, 255, 255, 0.12);
  --panel-border: rgba(255, 255, 255, 0.22);
  --text: #fff;
  --gold: #ffd166;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Baloo 2", "Trebuchet MS", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ---------- Map screen ---------- */
#mapScreen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  flex: 0 0 auto;
  gap: 8px;
  flex-wrap: wrap;
}
.map-head .title { font-size: clamp(20px, 6vw, 30px); }
.map-head-right { display: flex; align-items: center; gap: 6px; }

.chip-pill {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
}

#mapScroll {
  position: relative;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
#mapPathSvg { position: absolute; top: 0; left: 0; width: 100%; pointer-events: none; }
#mapNodes { position: relative; width: 100%; }

.map-node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--panel-border);
  background: linear-gradient(180deg, #6e3f92, #4a2766);
  color: #fff;
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35);
}
.map-node .n-num { font-size: 20px; line-height: 1; }
.map-node .n-stars { font-size: 11px; color: var(--gold); letter-spacing: 1px; min-height: 12px; }
.map-node.locked {
  background: rgba(255,255,255,0.07);
  border-color: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.45);
  cursor: default;
  box-shadow: none;
}
.map-node.done {
  background: linear-gradient(180deg, #43b86f, #2c8a4e);
  border-color: rgba(255,255,255,0.4);
}
.map-node.current {
  background: linear-gradient(180deg, var(--pink), var(--pink-dark));
  border-color: #fff;
  animation: nodePulse 1.4s infinite;
}
@keyframes nodePulse {
  0%,100% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 6px 14px rgba(0,0,0,0.35); }
  50% { transform: translate(-50%, -50%) scale(1.1); box-shadow: 0 0 24px rgba(255,95,162,0.8); }
}

.map-decor {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  opacity: 0.6;
  pointer-events: none;
}

/* ---------- Game screen ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud { padding: 10px 4px 6px; flex: 0 0 auto; }

.hud-row { display: flex; align-items: center; justify-content: space-between; }

.hud-title {
  font-size: clamp(20px, 6vw, 28px);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 3px 0 rgba(0,0,0,0.25);
}

.title {
  font-size: clamp(26px, 7vw, 38px);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 3px 0 rgba(0,0,0,0.25);
}
.title span { color: var(--gold); }
.title .heart { color: var(--pink); animation: beat 1.2s infinite; display: inline-block; }
@keyframes beat { 0%,100%{transform:scale(1)} 15%{transform:scale(1.25)} 30%{transform:scale(1)} 45%{transform:scale(1.18)} }

.icon-btn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  color: #fff;
  font-size: 20px;
  width: 44px; height: 44px;
  cursor: pointer;
  flex: 0 0 auto;
}

.stats { gap: 8px; margin-top: 10px; }
.stat {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 8px 10px;
  text-align: center;
  min-width: 0;
}
.stat.goal { flex: 2; }
.stat .label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.7;
}
.stat .value { font-size: clamp(16px, 5vw, 22px); font-weight: 800; }

.chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: clamp(13px, 4vw, 17px);
  background: rgba(0,0,0,0.22);
  border-radius: 999px;
  padding: 1px 9px;
  white-space: nowrap;
}
.chip.done { background: rgba(76, 217, 123, 0.35); }

.progress {
  margin-top: 6px;
  height: 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.25);
  overflow: hidden;
}
#progressBar {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--gold), var(--pink));
  transition: width 0.35s ease;
}

/* ---------- Board ---------- */
#boardWrap {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#board { touch-action: none; }

.combo-toast {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translate(-50%, 0) scale(0.6);
  font-size: clamp(28px, 9vw, 46px);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255,209,102,0.8), 0 3px 0 var(--pink-dark);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.combo-toast.show { animation: pop 0.9s ease forwards; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.5); }
  25% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  70% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -22px) scale(1); }
}

.armed-hint {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- Booster bar ---------- */
#footer { flex: 0 0 auto; padding: 8px 4px 12px; }
#boosterBar { display: flex; gap: 10px; justify-content: center; }
.booster-btn {
  position: relative;
  width: 58px; height: 58px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  font-size: 26px;
  cursor: pointer;
  color: #fff;
}
.booster-btn .b-count {
  position: absolute;
  top: -6px; right: -6px;
  background: linear-gradient(180deg, var(--gold), #e0a32e);
  color: #4a2766;
  border-radius: 999px;
  min-width: 22px; height: 22px;
  font-size: 13px;
  font-weight: 900;
  line-height: 22px;
  padding: 0 4px;
}
.booster-btn.empty { opacity: 0.55; }
.booster-btn.empty .b-count { background: rgba(255,255,255,0.25); color: #fff; }
.booster-btn.armed {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(255,209,102,0.7);
  background: rgba(255,209,102,0.2);
}

/* ---------- Overlay / cards ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 8, 32, 0.72);
  backdrop-filter: blur(6px);
  z-index: 20;
  padding: 20px;
}
.card {
  background: linear-gradient(160deg, #5a2c79, #3a1c52);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  max-height: 90dvh;
  overflow-y: auto;
}
.card.small { max-width: 320px; padding: 22px 20px; }
.card h1 { margin: 0 0 8px; font-size: 30px; }
.card h1 span { color: var(--gold); }
.card p { margin: 0 0 14px; line-height: 1.5; opacity: 0.92; }
.ov-stats { margin: 0 0 16px; font-size: 15px; opacity: 0.95; }
.ov-stats .big { font-size: 30px; font-weight: 900; color: var(--gold); display: block; }
.ov-stats .coin-earn { font-weight: 900; color: var(--gold); }

.ov-stars-row { min-height: 0; margin-bottom: 4px; }
.ov-star {
  display: inline-block;
  font-size: 44px;
  color: rgba(255,255,255,0.2);
  margin: 0 4px;
}
.ov-star.lit {
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255,209,102,0.9);
  transform: scale(0);
  animation: starPop 0.5s ease forwards;
}
@keyframes starPop {
  0% { transform: scale(0) rotate(-40deg); }
  70% { transform: scale(1.3) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

.ov-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.play-btn {
  background: linear-gradient(180deg, var(--pink), var(--pink-dark));
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  padding: 12px 22px;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 5px 0 #b62e6a, 0 10px 20px rgba(0,0,0,0.3);
  transition: transform 0.08s ease;
}
.play-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b62e6a; }
.play-btn.alt {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 5px 0 rgba(0,0,0,0.3);
}
.play-btn.alt:active { box-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.play-btn.gold {
  background: linear-gradient(180deg, var(--gold), #e0a32e);
  color: #4a2766;
  box-shadow: 0 5px 0 #a87a1c, 0 10px 20px rgba(0,0,0,0.3);
}
.play-btn.gold:active { box-shadow: 0 2px 0 #a87a1c; }
.play-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Shop ---------- */
.card.shop h1 { margin-bottom: 4px; }
.shop-coins { display: inline-block; margin-bottom: 14px; }
#shopCards { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.shop-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 10px 12px;
  text-align: left;
}
.s-emoji { font-size: 30px; flex: 0 0 auto; }
.s-body { flex: 1 1 auto; min-width: 0; }
.s-name { font-weight: 800; font-size: 16px; }
.s-owned { opacity: 0.7; font-size: 13px; font-weight: 700; }
.s-desc { font-size: 12px; opacity: 0.8; line-height: 1.35; }
.s-buy {
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--gold), #e0a32e);
  border: none;
  color: #4a2766;
  font-family: inherit;
  font-weight: 900;
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 #a87a1c;
}
.s-buy:active { transform: translateY(2px); box-shadow: 0 1px 0 #a87a1c; }
.s-buy:disabled { opacity: 0.45; cursor: default; }

/* ---------- Level intro ---------- */
.in-objective { font-size: 18px; font-weight: 800; color: var(--gold); }
.in-intro {
  background: rgba(255,209,102,0.14);
  border: 1px solid rgba(255,209,102,0.4);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
}
.in-meta { display: flex; gap: 14px; justify-content: center; margin-bottom: 16px; font-weight: 700; opacity: 0.9; }
.in-best { color: var(--gold); }
.qb-coins { opacity: 0.75; font-size: 13px; }

/* ---------- Account ---------- */
#accountBtn { display: none; }
body.cloud-on #accountBtn { display: block; }
#accountBtn.signed-in {
  background: linear-gradient(180deg, var(--pink), var(--pink-dark));
  font-weight: 900;
  font-size: 18px;
}
.acc-input {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: rgba(0,0,0,0.25);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  outline: none;
}
.acc-input:focus { border-color: var(--pink); }
.acc-input::placeholder { color: rgba(255,255,255,0.45); }
.acc-error { color: #ff8a8a; font-size: 13px; font-weight: 700; min-height: 18px; margin-bottom: 10px; }
.acc-note { font-size: 13px; opacity: 0.8; }
