:root {
  --ink: #1d1b3a;
  --accent: #ff7a59;
  --accent-2: #5b4bdb;
  --gem: #2ee6a6;
  --gold: #ffc83d;
  --panel: rgba(255, 255, 255, 0.95);
  --soft: #f4f2fa;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(#7cb6ff 0%, #bfd9ff 55%, #f3e9ff 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
button { font-family: inherit; }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
/* Block container: score column flows on the left, pause + combo are pinned, and any widget a
   feature module appends to #hud simply stacks under the score instead of reflowing the bar. */
#hud {
  position: fixed;
  top: max(12px, var(--safe-top));
  left: 16px;
  right: 16px;
  pointer-events: none;
  z-index: 5;
}
#pauseBtn { position: absolute; top: 0; right: 0; }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.score { font-size: 44px; font-weight: 700; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.18); line-height: 1; }
.gems { font-size: 22px; font-weight: 700; color: #0b8f62; }
#hud .gems { color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.icon-btn {
  pointer-events: auto;
  width: 48px; height: 48px;
  border: 0; border-radius: 14px;
  background: rgba(255,255,255,.85);
  color: var(--ink);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
}

/* Active power-up chips with draining timer bars */
.pu-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; max-width: calc(100vw - 150px); }
.pu-chip {
  --c: var(--accent-2);
  display: flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 3px;
  border-radius: 999px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
  animation: chipIn .3s cubic-bezier(.2,1.6,.4,1);
}
.pu-ico {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--c);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700; color: #fff; line-height: 1;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.15);
}
.pu-bar { width: 38px; height: 7px; border-radius: 4px; background: rgba(29,27,58,.12); overflow: hidden; }
.pu-bar b { display: block; width: 100%; height: 100%; background: var(--c); transform-origin: left center; }
.pu-chip.low .pu-ico { animation: lowBlink .3s ease-in-out infinite alternate; }
.pu-chip.landing .pu-bar { animation: lowBlink .4s ease-in-out infinite alternate; }
@keyframes chipIn { from { transform: scale(.4); opacity: 0; } }
@keyframes lowBlink { to { opacity: .35; } }

/* Combo meter (top centre) */
.combo {
  position: absolute; left: 50%; top: 0;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.18);
}
.combo b { display: inline-block; font-size: 34px; line-height: 1; color: #ffd23f; }
.combo small { font-size: 11px; font-weight: 700; letter-spacing: .22em; }
.combo-bar { width: 64px; height: 5px; margin-top: 3px; border-radius: 3px; background: rgba(255,255,255,.35); overflow: hidden; }
.combo-bar i { display: block; height: 100%; background: #fff; transform-origin: left center; }
.combo em {
  margin-top: 4px; padding: 1px 8px;
  border-radius: 999px;
  background: #ffd23f; color: var(--ink);
  font-style: normal; font-size: 12px; font-weight: 700;
  text-shadow: none; white-space: nowrap;
}

/* Toast banners + floating popups */
.toasts {
  position: fixed; left: 16px; right: 16px;
  top: calc(max(12px, var(--safe-top)) + 156px);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
  z-index: 40;
}
.toast {
  --c: var(--accent-2);
  max-width: 100%;
  padding: 8px 18px;
  border: 3px solid rgba(255,255,255,.9);
  border-radius: 999px;
  background: var(--c);
  color: #fff;
  font-size: 20px; font-weight: 700; text-align: center;
  text-shadow: 0 2px 0 rgba(0,0,0,.22);
  box-shadow: 0 8px 22px rgba(29,27,58,.25), inset 0 -3px 0 rgba(0,0,0,.15);
}
.popups { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 6; }
.popup {
  position: absolute; left: 0; top: 0;
  font-size: 22px; font-weight: 700; white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,.3), 0 0 12px rgba(0,0,0,.15);
  opacity: 0;
  will-change: transform, opacity;
}

/* Tutorial hint bubble */
.tip {
  position: fixed; left: 0; right: 0;
  bottom: calc(max(16px, var(--safe-bottom)) + 16vh);
  width: max-content; max-width: calc(100vw - 32px);
  margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px 10px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 10px 30px rgba(29,27,58,.28);
  font-size: 18px; font-weight: 700;
  pointer-events: none;
  z-index: 7;
  animation: tipIn .35s cubic-bezier(.2,1.5,.4,1), tipBob 1.2s ease-in-out .35s infinite;
}
.tip-ico {
  flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 20px;
}
@keyframes tipIn { from { transform: translateY(20px) scale(.8); opacity: 0; } }
@keyframes tipBob { 50% { transform: translateY(-6px); } }

/* ---------- Menu ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: max(28px, calc(var(--safe-top) + 12px)) 16px max(16px, var(--safe-bottom));
  overflow-y: auto;
  touch-action: pan-y;
  pointer-events: none;
  z-index: 10;
}
.screen > * { pointer-events: auto; }
.logo { text-align: center; margin-top: 3vh; pointer-events: none; }
.logo h1 {
  margin: 0;
  font-size: clamp(56px, 18vw, 88px);
  line-height: .86;
  color: #fff;
  text-shadow: 0 5px 0 var(--accent-2), 0 14px 30px rgba(29,27,58,.3);
}
.logo h1 span { display: block; color: var(--accent); text-shadow: 0 5px 0 #c94a2c, 0 14px 30px rgba(29,27,58,.3); }
.tagline { margin: 14px 0 0; color: #fff; font-weight: 700; font-size: 15px; text-shadow: 0 2px 0 rgba(0,0,0,.18); }
.menu-card {
  width: min(360px, 100%);
  flex: none;
  padding: 18px;
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(29,27,58,.25);
  text-align: center;
  display: flex; flex-direction: column; gap: 10px;
  animation: panelIn .35s cubic-bezier(.2,1.3,.4,1);
}
.play-btn { animation: playPulse 1.6s ease-in-out infinite; }
@keyframes playPulse { 50% { scale: 1.035; } }
.menu-corner {
  position: fixed;
  top: max(12px, var(--safe-top));
  right: 16px;
  display: none;
  gap: 8px;
  z-index: 11;
}
body[data-screen="menu"] .menu-corner { display: flex; }
@media (max-height: 640px) {
  .logo h1 { font-size: 48px; }
  .tagline { display: none; }
  .menu-card { padding: 14px; gap: 8px; }
}

/* ---------- Panels ---------- */
.panel {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  touch-action: pan-y;
  padding: 22px 20px;
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(29, 27, 58, .25);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
  animation: panelIn .28s cubic-bezier(.2,1.3,.4,1);
}
.panel.wide { width: min(520px, calc(100vw - 32px)); }
@keyframes panelIn { from { opacity: 0; scale: .9; } }

h1 { margin: 0 0 4px; font-size: 52px; line-height: .9; color: var(--accent-2); }
h2 { margin: 0; font-size: 32px; line-height: 1.1; }
h3 { margin: 8px 0 0; font-size: 18px; opacity: .7; }
.sub { margin: 0; font-size: 15px; opacity: .7; }
.muted { opacity: .6; font-size: 13px; }

.stats { display: flex; justify-content: center; gap: 22px; margin: 4px 0 6px; }
.stats small { display: block; font-size: 12px; letter-spacing: .1em; opacity: .55; }
.stats b { font-size: 28px; }
.gem-num { color: #0b8f62; }

.extras { display: flex; flex-direction: column; gap: 8px; }
.extras:empty { display: none; }
.stage { display: flex; flex-direction: column; gap: 10px; }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: var(--accent-2);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.18);
  transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.btn.big { font-size: 24px; padding: 16px; background: var(--accent); }
.btn.ghost { background: #ece9f6; color: var(--ink); }
.btn.reward { background: #1fbf86; }
.btn.gold { background: linear-gradient(#ffd56a, #f5a524); color: #5a3300; }
.btn:disabled { opacity: .4; pointer-events: none; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.hint { margin: 2px 0 0; font-size: 13px; opacity: .6; line-height: 1.5; }

/* ---------- Game over ---------- */
.revive-score { display: flex; align-items: baseline; justify-content: center; gap: 4px; }
.revive-score b { font-size: 54px; line-height: 1; color: var(--accent-2); }
.revive-score small { font-size: 20px; font-weight: 700; opacity: .5; }
.revive-timer { height: 8px; border-radius: 4px; background: #ece9f6; overflow: hidden; }
.revive-timer i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ffd23f); transform-origin: left center; }
#reviveBtn { animation: playPulse 1.4s ease-in-out infinite; }
.badge {
  align-self: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: linear-gradient(#ffe08a, #f5a524);
  color: #6b3b00;
  font-weight: 700; letter-spacing: .08em;
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
  animation: badgePop .6s cubic-bezier(.2,1.6,.4,1), badgeGlow 1.6s ease-in-out .6s infinite;
}
@keyframes badgePop { from { scale: .3; opacity: 0; } }
@keyframes badgeGlow { 50% { box-shadow: 0 4px 0 rgba(0,0,0,.12), 0 0 22px rgba(255,200,61,.9); } }
.run-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.run-stat { padding: 7px 2px; border-radius: 12px; background: var(--soft); }
.run-stat b { display: block; font-size: 19px; line-height: 1.1; }
.run-stat small { display: block; font-size: 10.5px; opacity: .6; white-space: nowrap; }

/* ---------- Shop ---------- */
.shop-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shop-head h2 { font-size: 28px; }
.shop-gems { padding: 4px 12px; border-radius: 999px; background: #e3fbf1; font-size: 20px; }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: #ece9f6; }
.tab {
  flex: 1;
  border: 0; border-radius: 10px;
  padding: 9px 4px;
  background: transparent;
  color: rgba(29,27,58,.6);
  font: inherit; font-size: 16px; font-weight: 700;
  cursor: pointer;
}
.tab.active { background: #fff; color: var(--accent-2); box-shadow: 0 2px 0 rgba(0,0,0,.08); }
.pane-note { margin: 0 0 8px; font-size: 13px; opacity: .6; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.skin {
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 10px 6px;
  background: var(--soft);
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.skin.equipped { border-color: var(--accent); }
.skin .ball { width: 44px; height: 44px; margin: 0 auto 6px; border-radius: 50%; box-shadow: inset -6px -8px 0 rgba(0,0,0,.18), inset 5px 6px 0 rgba(255,255,255,.35); }
.skin .name { font-weight: 700; font-size: 15px; }
.skin .price { font-size: 13px; opacity: .7; }
.skin.locked .ball { filter: grayscale(.6) brightness(.9); }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.upg-list, .store-list { display: flex; flex-direction: column; gap: 8px; }
.upg {
  --c: var(--accent-2);
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: 16px;
  background: var(--soft);
  text-align: left;
}
.upg-ico {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--c); color: #fff;
  font-size: 22px; font-weight: 700;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15);
}
.upg-info { min-width: 0; }
.upg-name { font-size: 16px; font-weight: 700; line-height: 1.1; }
.upg-meta { font-size: 12px; opacity: .7; }
.pips { display: flex; gap: 3px; margin: 5px 0 3px; }
.pips i { width: 16px; height: 6px; border-radius: 3px; background: rgba(29,27,58,.12); }
.pips i.on { background: var(--c); }
.upg-buy { min-width: 78px; padding: 9px 10px; font-size: 15px; }
.upg-buy.poor { background: #b9b4d6; }

.store-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: var(--soft);
  color: var(--ink);
  font: inherit; text-align: left;
  cursor: pointer;
}
.store-item.featured { border-color: var(--gold); background: #fff8e4; }
.store-item:disabled { opacity: .6; cursor: default; }
.store-ico { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #fff; font-size: 22px; color: #0b8f62; }
.store-label { flex: 1; font-size: 17px; font-weight: 700; line-height: 1.15; }
.store-label small { display: block; font-size: 12px; font-weight: 500; opacity: .65; }
.store-price { padding: 7px 12px; border-radius: 12px; background: var(--accent-2); color: #fff; font-weight: 700; }
.store-tag {
  position: absolute; top: -9px; right: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--gold); color: #5a3300;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
}

/* ---------- Ads / purchase overlays (always above every panel) ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 25, .82);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.ad-box { color: #fff; text-align: center; width: min(320px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px; }
.ad-title { font-size: 26px; font-weight: 700; }
.ad-sub { opacity: .7; }
.ad-count { font-size: 64px; font-weight: 700; color: var(--gem); }

@media (prefers-reduced-motion: reduce) {
  .play-btn, #reviveBtn, .tip, .badge { animation: none; }
}

/* Battle entry on the menu card */
.battle-btn { background: linear-gradient(135deg, #8a5cff, #5b2bd6); font-size: 20px; box-shadow: 0 4px 0 #3c1a9a; }
.battle-btn small { font-size: 13px; opacity: .8; font-weight: 500; }

/* Premium skin cards */
.skin { position: relative; }
.skin .rar { position: relative; z-index: 1; display: block; width: max-content; max-width: 100%; margin: -2px auto 5px; padding: 1px 8px; border-radius: 99px; color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skin:not(:has(.rar)) .ball { margin-top: 20px; }
.skin.rar-legendary { background: linear-gradient(160deg, #fff7d6, #f4f2fa 60%); }
.skin.rar-epic { background: linear-gradient(160deg, #f1e6ff, #f4f2fa 60%); }
.skin.rar-legendary .ball { box-shadow: 0 0 14px rgba(240,164,0,.55), inset -6px -8px 0 rgba(0,0,0,.18), inset 5px 6px 0 rgba(255,255,255,.35); }

/* SVG icon sprite (assets/icons/icons.svg, Kenney CC0): colour follows currentColor */
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; fill: currentColor; flex: none; }
.pu-ico .ic, .upg-ico .ic { width: 70%; height: 70%; vertical-align: middle; }
.onl-tile-ico.ic { width: 22px; height: 22px; }

/* Skin collection filters */
.skin-filters { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; scrollbar-width: none; touch-action: pan-x; }
.skin-filters button { flex: none; border: 0; border-radius: 99px; padding: 7px 12px; min-height: 34px; background: #ece9f6; font: inherit; font-weight: 700; font-size: 13px; color: var(--ink); cursor: pointer; white-space: nowrap; }
.skin-filters button.on { background: var(--accent-2); color: #fff; }
.skin.aura-skin .ball { box-shadow: 0 0 14px rgba(255,210,63,.7), inset -6px -8px 0 rgba(0,0,0,.18); }

/* Live events (Haunted Hollow): core-marble icon, event filter chip and countdown banner */
.skin .ball .core-ico { display: grid; place-items: center; width: 100%; height: 100%; font-size: 24px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.skin-filters button.ev { background: linear-gradient(135deg, #ff7a12, #6a2bb8); color: #fff; }
.skin-filters button.ev.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #ff7a12; }
.event-banner { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 2px 8px; padding: 10px 14px; border-radius: 14px; background: linear-gradient(135deg, #1b0b2e, #3a1450 55%, #6a2410); color: #ffd9a8; font-size: 13px; }
.event-banner b { color: #ffb347; font-size: 15px; }
